【问题标题】:Telegram bot doesn't respond to message in group rather replies for the same in personal chatTelegram bot 不会在群组中回复消息,而是在个人聊天中回复相同的消息
【发布时间】:2018-10-16 19:07:28
【问题描述】:

使用节点 js 的 Telegram bot 不在群内回复。当我在群组中发短信时,它会立即在我的个人聊天中回复我。 -该组是一个超级组 - 机器人是管理员 - 隐私设置被禁用 然而还是有这个问题。我该怎么做??

const TelegramBot = require('node-telegram-bot-api');
const token = 'my bot_token here';
const bot = new TelegramBot(token, {polling: true});
bot.on('message', (msg) => {
var Hi = "hi";
if (msg.text.toString().toLowerCase().indexOf(Hi) === 0) {
    bot.sendMessage(msg.from.id, "Hello  " + msg.from.first_name);
} });

【问题讨论】:

  • 你有sn-ps的代码吗?到目前为止,您尝试过什么?
  • 我只是想让我的机器人欢迎新成员..也回应任何问候,比如打个招呼或你好..因为我的机器人根本没有在群组中回复..所以我是无法检查代码的欢迎部分..但是对 hi 或 hello 的回复有效,但即使我 /start 它并在组中打招呼,它也会私下回复 n 而不是在组本身中..将添加代码 sn-p下面..
  • 用代码 sn-p 更新了问题。请查看。

标签: javascript node.js telegram telegram-bot


【解决方案1】:

你应该使用 chat.id 而不是 user.id:

const TelegramBot = require('node-telegram-bot-api');
const token = 'my bot_token here';
const bot = new TelegramBot(token, {polling: true});
bot.on('message', (msg) => {
var Hi = "hi";
if (msg.text.toString().toLowerCase().indexOf(Hi) === 0) {
    bot.sendMessage(msg.chat.id, "Hello  " + msg.from.first_name);
} });

【讨论】:

  • 另一个注意事项是该机器人必须是该组的管理员和管理员
猜你喜欢
  • 2022-11-11
  • 2017-08-07
  • 2021-12-18
  • 2021-04-06
  • 2020-10-04
  • 2018-10-05
  • 2017-11-28
  • 2021-08-08
  • 1970-01-01
相关资源
最近更新 更多