简体   繁体   English

如何使用Telegraf在电报频道中发送消息?

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

相关问题 Telegram:无法使用 Telegraf (NodeJs) 将消息/照片发送到频道 - Telegram: Cannot send message/photo into a channel with Telegraf (NodeJs) 如何使用 Telegraf.js Node.js 在 Telegram Bot 中发送私人消息 - How to send private message in Telegram Bot using Telegraf.js Node.js 如何使用 npm 库 Telegraf 从数据库中的 id 列表一次向所有电报机器人用户发送消息 - How to send messages to all telegram bot users from a list of ids in a database at once using npm library Telegraf 如何使用 telegraf(电报框架)将聊天 ID 保存到文件中 - How to save chat id to a file using telegraf (telegram framework) 使用电报机器人 (telegraf)、nodejs 发送降价文本 - Send markdown text with telegram bot (telegraf), nodejs 如何将消息发送到特定频道? - How to send a message to a specific channel? 如何通过 Bot Framework 使用 Telegram 通道在回发按钮中发送对象? - How to send Object in a postback button using Telegram channel via Bot Framework? 如何使用 JS 和 Chrome 控制台向频道发送 Discord 消息? - How to send a Discord message to a channel using JS & Chrome Console? 如何使用discord.js向特定频道发送消息 - how to send a message to a specific channel using discord.js 如何正确实现从机器人到电报频道的消息转发? - How to properly implement the forwarding of a message from a bot to a telegram channel?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM