【问题标题】:Telegram API send messages with php or javascript? [closed]Telegram API 使用 php 或 javascript 发送消息? [关闭]
【发布时间】:2015-07-04 21:08:14
【问题描述】:

如何通过用户号码向用户发送消息?我看到了这个网站http://notificatio.divshot.io/,但是没有办法删除它在消息中的引用。

【问题讨论】:

  • 嗨!只需写信给 support@notificatio.me,主题为:“请删除参考资料 [StackOverflow]”。

标签: javascript php api telegram


【解决方案1】:

您可以使用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 用户免受营销机器人发送垃圾邮件的机制......这就是你需要的首先发起与机器人的对话。

【讨论】:

  • 谢谢,但是我如何用所有数字动态添加组?
  • 我所知道的最接近的是深度链接功能,core.telegram.org/bots#deep-linking。我不认为你可以用一系列数字开始一个组,因为这会是侵入性的,在 Telegram 中,最终用户必须是采取将机器人添加到他们的联系人列表等操作的人。你可以使用 deep -linking 在用户单击链接时动态启动组或执行操作。链接格式类似于telegram.me/yourbot?startgroup=CustomBotGroup
  • 但是可以插入电话号码而不是聊天ID吗?就像notificatio.divshot.io 使用数字电话
  • 电话号码是您尝试与之交互的用户的号码还是您的机器人(将发送消息的应用程序帐户)的地址?
  • 用户的电话号码..我要发送通知
猜你喜欢
  • 2015-10-15
  • 2014-08-11
  • 2014-12-28
  • 1970-01-01
  • 2021-07-06
  • 1970-01-01
  • 2023-03-23
  • 1970-01-01
  • 2016-05-09
相关资源
最近更新 更多