node.js - 限制nodejs电报机器人上的用户
问题描述
我目前有一个电报机器人,可以为我的组织用户提供常见问题解答,但我需要对其进行限制,以便只有为指导付费的某些人才能使用该产品
无论如何我可以要求人们输入存储信息的用户 ID 号,因此如果代码中的列表中没有,则无法访问机器人
我的机器人目前是用 nodejs 语言编写的(基于这个 repo)。
[
{
"triggers": [
"hello",
"hi"
],
"replies": [
{
"reply": "Hi Im your Personal Lion Bot \r\n\r\nWhat do you want to focus on today\r\n\r\n>Trading Help\r\n\r\n>Business Help\r\n\r\n>Mindset\r\n\r\n>Schedule\r\n\r\n>Just Started\r\n\r\n>Help",
"type": "text"
}
]
},
{
"triggers": [
"trading",
"Trading"
],
"replies": [
{
"reply": "Ok you want to focus on trading\r\n\r\nHeres is what I can show you\r\n\r\n>Our Schedule\r\n\r\n>A Trading Gameplan\r\n\r\n>Trade Ideas\r\n\r\n>Trading Products",
"type": "text"
}
]
}
]
解决方案
You need to know your paying users' ID, then you answer their messages only if msg.from.id
is in your list of allowed users.
Something like:
function check_if_allowed(id) {
...
}
bot.on('message', (msg) => {
if (check_if_allowed(msg.from.id)) {
...
}
})
To find their ID depends on how you register them in your organization.
Add more details and code if you need further help
推荐阅读
- visual-studio-code - 事件 VSCode API CodeAction 接受
- asp.net-core-3.1 - 在 .net core 3.1 中使用 JsonSerialiser 和 JsonDeserialiser 时,我遇到了找不到类型或名称空间的问题
- python - Python基类的动态覆盖方法
- javascript - Odoo11 - 多公司网站门户用户仪表板
- javascript - Node Express - 获取无法 GET 或请求返回 html 页面
- reactjs - 在滚动视图中使用 snapToInterval 或 pagingEnabled 时,我如何知道显示的页面是什么?
- agora.io - 在 Agora Voice call sdk 中获取会员数量
- list - “NoneType”对象不可迭代:循环列表
- sql - 表更新为每一行设置正确的日期时间
- xcode - 无法在我的手机上尝试应用程序的 vs 代码上构建 iOS 应用程序