[英]Telegram: Cannot send message/photo into a channel with Telegraf (NodeJs)
I would send a message on telegram channel with telegraf.我会用电报在电报频道上发送一条消息。 I'v einvited the bot and put him admin.
我已经邀请了机器人并让他成为管理员。
I've tested with this code:我已经用这个代码测试过:
bot.on('text', (ctx) => {
// Explicit usage
ctx.telegram.sendMessage(ctx.message.chat.id, `Hello ${ctx.state.role}`)
// Using context shortcut
// ctx.reply(`Hello ${ctx.state.role}`)
})
bot.launch();
But it replies only if i wrote on private.但它只有在我私下写信时才会回复。 So why it doesn't work on a channel?
那么为什么它在频道上不起作用呢? Than how can i send a message in that channel without a command?
我如何在没有命令的情况下在该频道中发送消息? (For example with and interval?
(例如与和间隔?
I i try this one:我试试这个:
bot.use((ctx) => {
console.log(ctx.message)
})
when i use the bot on private chat (with him) it returns all the message data.当我在私人聊天(与他)中使用机器人时,它会返回所有消息数据。 On the channel i receive undefined
在频道上我收到 undefined
In your case CTX have current chat info, if you want to send message to channel provide correct id as documented for Telegraf sendMessage :在您的情况下,CTX 有当前的聊天信息,如果您想向频道发送消息,请提供Telegraf sendMessage记录的正确 ID:
telegram.sendMessage(process.env.TELEGRAM_CHANNEL, ctx.message.text);
I am using a bot for a public channel, so in my case it's:我将机器人用于公共频道,因此在我的情况下是:
TELEGRAM_CHANNEL=@MY_PUBLIC_CHANNEL_NAME
The channel name is available in channel info settings t.me/MY_PUBLIC_CHANNEL_NAME
频道名称在频道信息设置
t.me/MY_PUBLIC_CHANNEL_NAME
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.