首页 > 解决方案 > 限制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"
            }
        ]
    }
]

标签: node.jsbotstelegramrestrict

解决方案


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


推荐阅读