如何通过用户号码向用户发送消息?我看到了这个网站http://notificatio.divshot.io/,但是没有办法删除它在消息中的引用。
问问题
20347 次
1 回答
4
您可以使用Telegram Bot API,它是 Telegram 服务的一个易于使用的 HTTP 接口。使用他们的BotFather创建机器人令牌。JavaScript (NodeJS) 使用示例:
var TelegramBot = require('telegrambot');
var api = new TelegramBot('<YOUR TOKEN HERE>');
// You can either use getUpdates or setWebHook to retrieve updates.
// getUpdates needs to be done on an interval and will contain all the
// latest messages send to your bot.
// Update the offset to the last receive update_id + 1
api.invoke('getUpdates', { offset: 0 }, function (err, updates) {
if (err) throw err;
console.log(updates);
});
// The chat_id received in the message update
api.invoke('sendMessage', { chat_id: <chat_id>, text: 'my message' }, function (err, message) {
if (err) throw err;
console.log(message);
});
该示例使用了我在项目中使用的NodeJS 库。
为了与用户开始对话,您可以使用深度链接功能。例如,您可以在您的网站上放置一个链接,如下所示:
https://telegram.me/triviabot?start=payload(如果你想使用一个自定义变量值,如身份验证 ID 等)
点击该链接将提示用户启动 Telegram 应用程序并将机器人添加到联系人列表中。然后,您将通过 getUpdates() 调用收到一条消息,其中包含该用户的 chat_id。然后,您可以使用此 chat_id 向用户发送任何您想要的消息。我不相信可以使用 Telegram Bot API 向手机号码发送消息,它们仅适用于 chat_id,因为这是一种保护 Telegram 用户免受营销机器人发送垃圾邮件的机制......这就是你需要的首先启动与机器人的对话。
于 2015-07-03T19:58:27.590 回答