gpt4 book ai didi

android - 向特定号码的电话发送短信

转载 作者:太空宇宙 更新时间:2023-11-03 13:40:41 26 4
gpt4 key购买 nike

我从 telegram.org 得到了 App api_idApp api_hashProduction configuration,我需要使用从这个方法 messages.sendMessage 用于向特定号码电话的 Telegram 发送文本消息(例如:+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

关于android - 向特定号码的电话发送短信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52568279/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com