android - 向特定号码的电话发送短信
问题描述
我得到了App api_id
,App api_hash
和Production configuration
from telegram.org
, 我需要使用 from 这个方法messages.sendMessage
来发送短信到特定号码电话的电报(例如:+1888888)。我如何使用这种方法。有没有简单的样本?
解决方案
我建议您使用 MTProto 上的顶层库来使事情变得更容易。例如,您可以使用Telethon。您应该使用SendMessageRequest来发送消息。创建客户端后,您可以这样调用它(在最新版本的 Telethon 中,电话号码会自动解析):
from telethon.tl.functions.messages import SendMessageRequest
client(SendMessageRequest('phone_number', 'hello'))
如果您使用的是 TDLib,则可以使用此功能(取自此处)或类似功能:
private static void sendMessage(long chatId, String message) {
// initialize reply markup just for testing
TdApi.InlineKeyboardButton[] row = {new TdApi.InlineKeyboardButton("https://telegram.org?1", new TdApi.InlineKeyboardButtonTypeUrl()), new TdApi.InlineKeyboardButton("https://telegram.org?2", new TdApi.InlineKeyboardButtonTypeUrl()), new TdApi.InlineKeyboardButton("https://telegram.org?3", new TdApi.InlineKeyboardButtonTypeUrl())};
TdApi.ReplyMarkup replyMarkup = new TdApi.ReplyMarkupInlineKeyboard(new TdApi.InlineKeyboardButton[][]{row, row, row});
TdApi.InputMessageContent content = new TdApi.InputMessageText(new TdApi.FormattedText(message, null), false, true);
client.send(new TdApi.SendMessage(chatId, 0, false, false, replyMarkup, content), defaultHandler);
}
不要忘记,您需要先将每个电话号码添加到用户的 Telegram 联系人中才能获得chatId
. 可以通过将电话号码数组传递给此函数来实现:
---functions---
contacts.importContacts#2c800be5 contacts:Vector<InputContact> = contacts.ImportedContacts
推荐阅读
- php - PHP Symfony DQL - 参数太少:查询定义了 1 个参数,但您只绑定了 0 个
- git - 如何在git中合并分支?
- javascript - 如何在javascript的单元测试用例中覆盖setInterval
- google-app-maker - Appmaker面板和画布高度
- python - 重新采样 Pandas 时间序列,以便日期表示每个月的 1 日
- c - 递归遍历目录时C中的gmtime不一致
- mysql - 使用给定的日期期间检查动态到期日期
- javascript - Config.get() 没有从文件中获取配置:“custom-environment-variables.json”Nodejs,JavaScript
- r - na.interpolation(data[, i], option) 中的错误:输入 x 不是数字
- solidity - 即使我的代码中没有构造函数,但我收到错误,如果您发送值,则应该支付构造函数