【发布时间】:2019-03-05 05:10:31
【问题描述】:
我从telegram.org得到了App api_id、App api_hash和Production configuration,我需要从这个方法中使用messages.sendMessage来发送短信到特定号码电话的电报(例如:+1888888)。我该如何使用这种方法。有没有简单的示例?
【问题讨论】:
我从telegram.org得到了App api_id、App api_hash和Production configuration,我需要从这个方法中使用messages.sendMessage来发送短信到特定号码电话的电报(例如:+1888888)。我该如何使用这种方法。有没有简单的示例?
【问题讨论】:
我建议您使用 MTProto 之上的顶层库来简化操作。例如,您可以使用Telethon。您应该使用SendMessageRequest 来发送消息。在creating a client 之后你可以这样调用它(在最新版本的 Telethon 中,电话号码会自动解析):
from telethon.tl.functions.messages import SendMessageRequest
client(SendMessageRequest('phone_number', 'hello'))
如果您使用的是 TDLib,则可以使用此函数(取自 here)或类似函数:
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
【讨论】:
ProcessBuilder 来运行您的python 脚本。见stackoverflow.com/questions/3468987/…