firebase - Twilio 聊天用户 (Node.js) 友好名称在访问令牌创建期间未注册
问题描述
我正在尝试将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()};
我在文档中找不到与此相关的任何内容。如果文档可以更清晰,那就太好了。特别是对于可编程聊天 SDK 部分。
例如,如果我们知道构造函数的参数(例如 ChatGrant 构造函数的参数是什么?),这对我们开发人员来说真的很有帮助。
谢谢一堆!
解决方案
在我看来,对于程序聊天,访问令牌仅用于访问聊天服务,因此没有与之相关的友好名称。成功进入聊天服务后,需要一个“服务角色”才能真正进行操作。在这个阶段,你开始使用“友好名称”
推荐阅读
- php - php+laravel 在哪里读取 db 连接字符串,因为运行时默认为用户 ID 未在我的应用程序的任何地方定义?
- vxworks - 如何在 Vxworks 的内核 shell 中使用 ping 命令?
- c++ - 如何修复ncurses?
- javascript - 我可以在回调方法中返回一个 Vue JS 组件吗?
- c# - CefSharp 进行 POST web api 调用 Win Forms c#
- php - Laravel Nova - 重新排序左侧导航菜单项
- pycurl - Curl 到 Pycurl 的翻译
- string - scala过滤具有多个逗号的字符串列表
- spring-boot - 在 Spring Boot 应用程序中持久化数据
- javascript - 如何使 ng-click 必须仅在 device-width<480px 时触发?