发送短信到特定的电话号码

时间:2018-09-29 12:15:41

标签: android telegram

我从App api_id获得了App api_hashProduction configurationtelegram.org,我需要使用此方法messages.sendMessage来向特定号码发送短信电话的电报(例如:+1888888)。如何使用这种方法。有没有简单的示例?

1 个答案:

答案 0 :(得分:3)

我建议您使用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);
}

别忘了,您需要首先将每个电话号码添加到用户的电报联系人中,以获得chatId。可以通过将一系列电话号码传递给此功能来实现:

---functions---
contacts.importContacts#2c800be5 contacts:Vector<InputContact> = contacts.ImportedContacts
相关问题