简体   繁体   English

Telegram:无法使用 Telegraf (NodeJs) 将消息/照片发送到频道

[英]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.

相关问题 如何使用Telegraf在电报频道中发送消息? - How to send message in a Telegram channel using Telegraf? Telegram:将照片发送到消息中而不显示与 Telegraf(NodeJs)的照片链接 - Telegram: Sen photo into a message without showing the photo link with Telegraf (NodeJs) 使用电报机器人 (telegraf)、nodejs 发送降价文本 - Send markdown text with telegram bot (telegraf), nodejs 如何在nodejs电报机器人(telegraf)中回复带有标题的照片 - how to reply a photo with caption in nodejs telegram bot (telegraf) 如何使用 Telegraf.js Node.js 在 Telegram Bot 中发送私人消息 - How to send private message in Telegram Bot using Telegraf.js Node.js 为什么电报机器人每次向频道发送照片的次数与按下上传照片按钮的次数一样多? - Why does a telegram bot every time send a photo to channel as many times as the Upload Photo button was pressed? 使用 nodejs 向 Discord 频道发送未经请求的消息 - Send an unsolicited message to Discord channel using nodejs 使用 nodejs 向微软团队频道发送消息 - Send message to microsoft teams channel using nodejs 电报Bot与Telegraf.js - 发送消息聊天 - Telegram Bot with Telegraf.js - Send messages to chat 如何使用 Telegraf API 发送本地存储的照片? - How to send a photo stored locally using telegraf API?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM