Пользователь Twilio Chat (Node.js) friendlyName не зарегистрирован при создании токена доступа - PullRequest
0 голосов
/ 29 марта 2020

Я пытаюсь интегрировать Программируемый чат Twilio SDK с моей функцией Firebase, написанной на Typescript.

Мне интересно, если friendlyName и атрибуты имеют значения может быть установлен во время создания токена доступа?

Я пробовал следующие подходы, но пока безрезультатно.

        const chatGrant = new ChatGrant({
            serviceSid: serviceSid,
            friendlyName : displayName,
            attributes : {
                profilePic : profilePic,
            }
        });
        const chatGrant = new ChatGrant({
            serviceSid: serviceSid,
        }, {
            friendlyName : displayName,
            attributes : {
                profilePic : profilePic,
            }
        });
        const chatGrant = new ChatGrant({
            serviceSid: serviceSid,
        });

        const token = new AccessToken(twilioAccountSid, twilioApiKey, twilioApiSecret);
        token.addGrant(chatGrant);
        token.identity = context.auth.uid;
        token.friendlyName : displayName,
        token.attributes : {
             profilePic : profilePic,
        }

Вот весь код:

        // displayName and profilePic initialization ...

        const AccessToken = require('twilio').jwt.AccessToken;
        const ChatGrant = AccessToken.ChatGrant;

        // Used when generating any kind of tokens
        const twilioAccountSid = functions.config().twilio.account_sid;
        const twilioApiKey = functions.config().twilio.api_key;
        const twilioApiSecret = functions.config().twilio.api_secret;

        // Used specifically for creating Chat tokens
        const serviceSid = functions.config().twilio.chat_service_sid;

        // Create a "grant" which enables a client to use Chat as a given user,
        // on a given device
        const chatGrant = new ChatGrant({
            serviceSid: serviceSid,
            friendlyName : displayName,
            attributes : {
                profilePic : profilePic,
            }
        });

        // Create an access token which we will sign and return to the client,
        // containing the grant we just created
        const token = new AccessToken(twilioAccountSid, twilioApiKey, twilioApiSecret);
        token.addGrant(chatGrant);
        token.identity = context.auth.uid;

        // Serialize the token to a JWT string
        return {identity: token.identity, token: token.toJwt()};

Я не смог найти ничего связанного с этим в документации. Было бы здорово, если бы документация могла быть более ясной . Особенно, для части Programmable Chat SDK.

Например, для нас, разработчиков, было бы действительно полезно, если бы мы знали аргументы конструктора (например, каковы аргументы конструктора ChatGrant?).

Спасибо, куча!

...