Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Token API #755

Open
DeepakDums1998 opened this issue Sep 24, 2022 · 2 comments
Open

Custom Token API #755

DeepakDums1998 opened this issue Sep 24, 2022 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@DeepakDums1998
Copy link

DeepakDums1998 commented Sep 24, 2022

Question
I have created a custom API in PHP for fetching tokens everything is going well but there is an issue in the conversation API

I am getting the following error
There was a problem getting the Conversation associated with this room. Error: There was a problem getting the Conversation associated with this room.

here is my API CODE which I have created

`
$requestdata = json_decode($request->getContent(), true);

    // Substitute your Twilio Account SID and API Key details
    $accountSid = env('TWILIO_ACCOUNT_SID');
    $apiKeySid = env('TWILIO_API_KEY_SID');
    $authtoken = '5fbd7ad7f6c7795fd3359c6d5550a0c5';
    $apiKeySecret = env('TWILIO_API_KEY_SECRET');
    $conversation_sid = env('TWILIO_CONVERSATIONS_SERVICE_SID');
    $identity = $requestdata['user_identity'];
    // Create an Access Token
    $token = new AccessToken(
        $accountSid,
        $apiKeySid,
        $apiKeySecret,
        3600,
        $identity
    );

    //Grant access to Video
    $grant = new VideoGrant();
    $grant->setRoom($requestdata['room_name']);
    $token->addGrant($grant);

    // // Create Chat grant
    $chatGrant = new ChatGrant();
    $chatGrant->setServiceSid($conversation_sid);
    $token->addGrant($chatGrant);
    $twilio = new Client(
        $accountSid,
        $authtoken
    );
    $conversation_service = $twilio->conversations->v1->services($conversation_sid)->conversations
        ->create(
            [
                "friendlyName" => $requestdata['room_name'],
                "uniqueName" => $requestdata['room_name']
            ]
        );
    // Serialize the token as a JWT
    // echo $token->toJWT();
    return response()->json([
        'token' => $token->toJWT(),
        'room_type' => 'group',
        'conversation_id' => $conversation_service->sid
    ]);`

Additional context
https://prnt.sc/2arWzh4uIvwJ

@DeepakDums1998 DeepakDums1998 added the question Further information is requested label Sep 24, 2022
@manjeshbhargav manjeshbhargav self-assigned this Sep 29, 2022
@manjeshbhargav
Copy link
Collaborator

Hi @DeepakDums1998 ,

Thanks for writing in with your question. The error raised usually has a code associated with it. Can you share it with me? Also, is there a way I can access a deployed version of your app? That will help me with debugging.

@runnermann
Copy link

Hi, We have the same issue. We are using java to create the custom token using the Twilio Helper Library. I do not see an error code associated with the error. Below are screen shots of the errors and the console.

Screenshot 2023-09-19 at 10 12 01 AM Screenshot 2023-09-19 at 10 11 19 AM

Here is how we are creating the token.
`
import com.twilio.Twilio;
import com.twilio.jwt.accesstoken.AccessToken;
import com.twilio.jwt.accesstoken.ChatGrant;
import com.twilio.jwt.accesstoken.VideoGrant;

VideoGrant roomGrant = new VideoGrant()
.setRoom(room);
ChatGrant chatGrant = new ChatGrant();
chatGrant.setServiceSid(serviceSid);

    token = new AccessToken.Builder(
            ACCOUNT_SID,
            twilioApiKey,
            twilioApiSecret
    )
            .identity(attendeeName)
            .grant(roomGrant)
            .grant(chatGrant)
            .build();

`

Any hints on how to work around this error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants