[英]How to send message in a Telegram channel using Telegraf?
I want to create a Bot that automatically keeps posting in a Telegram channel.I am using Node.js. 我想创建一个自动保持在Telegram频道中发布的Bot。我正在使用Node.js. I am using Telegraf.js wrapper for Telegram API. 我正在为Telegram API使用Telegraf.js包装器。 You may even suggest any other suitable wrapper for this task. 您甚至可以建议其他适合此任务的包装器。
Telegraph documentation is very comprehensive and you can find it at https://telegraf.js.org . 电报文档非常全面,您可以在https://telegraf.js.org上找到它。 I'm sure it will answer most of your questions. 我相信它将回答您的大多数问题。
If you want your bot to keep posting messages in a channel, simply execute this line of code in a loop: 如果您希望机器人继续在通道中发布消息,只需在循环中执行以下代码即可:
ctx.telegram.sendMessage(CHANNEL_ID, 'your message')
Don't forget to replace CHANNEL_ID
and 'your message'
with your own values. 不要忘记用您自己的值替换CHANNEL_ID
和'your message'
。
If your Channel is public. 如果您的频道是公开的。 You need set admin in you channel. 您需要在频道中设置管理员。 Use: ctx.telegram.sendMessage(Channels_Username, 'your message')
使用: ctx.telegram.sendMessage(Channels_Username, 'your message')
Example: 例:
ctx.telegram.sendMessage('@birodarlar', 'Hi everyone')
If your Channel is Private You need set admin in you channel.Use: ctx.telegram.sendMessage(Channels_id, 'your message')
如果您的频道是私人频道,则需要在频道中设置管理员。使用: ctx.telegram.sendMessage(Channels_id, 'your message')
Example: 例:
ctx.telegram.sendMessage('-145542325454', 'Hi everyone')
you can wiev your channels id with this link https://core.telegram.org/bots/api#sendmessage for 5 minutes you need public it and know channel id with url parsing 您可以使用此链接https://core.telegram.org/bots/api#sendmessage来保留您的频道ID 5分钟,您需要将其公开,并通过网址解析了解频道ID
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.