【发布时间】:2015-07-04 21:08:14
【问题描述】:
如何通过用户号码向用户发送消息?我看到了这个网站http://notificatio.divshot.io/,但是没有办法删除它在消息中的引用。
【问题讨论】:
-
嗨!只需写信给 support@notificatio.me,主题为:“请删除参考资料 [StackOverflow]”。
标签: javascript php api telegram
如何通过用户号码向用户发送消息?我看到了这个网站http://notificatio.divshot.io/,但是没有办法删除它在消息中的引用。
【问题讨论】:
标签: javascript php api telegram
您可以使用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 library。
为了与用户开始对话,您可以使用深层链接功能。例如,您可以像这样在您的网站上放置一个链接:
https://telegram.me/triviabot?start=payload(如果您想使用一个自定义变量值,例如身份验证 ID 等)
点击该链接将提示用户启动 Telegram 应用程序并将机器人添加到联系人列表中。然后,您将通过 getUpdates() 调用收到一条消息,其中包含该用户的 chat_id。然后,您可以使用此 chat_id 向用户发送任何您想要的消息。我不相信可以使用 Telegram Bot API 向手机号码发送消息,它们仅适用于 chat_id,因为这是一种保护 Telegram 用户免受营销机器人发送垃圾邮件的机制......这就是你需要的首先发起与机器人的对话。
【讨论】: