c#wtelegramclient telegram-api如何通过编程单击“电信机器人”的消息中的按钮
该程序与Telegram-Bot通信。短信发送到机器人。机器人响应消息。答案包含3个按钮。问题:如何以编程方式单击按钮?
创建电报客户端:
_client = new WTelegram.Client(Config):
_user = await _client.LoginUserIfNeeded();
查找机器人:
var contacts = await _client.Contacts_Search("@Search_bot", 20);
contacts.users.TryGetValue(1911124859, out peerBot));
向机器人发送请求(消息):
var message = await _client.SendMessageAsync(peerBot, "REQUEST");
我们得到答案:
var differenceMessages = await _client.Updates_GetDifference(state.pts, state.date, state.qts);
我们理解答案。我们找到一个按钮。 如何将消息发送给我们点击按钮的机器人?
TL.Message tLMessage = null;
if (differenceMessages != null)
{
if(differenceMessages.NewMessages != null)
{
foreach (var difference in differenceMessages.NewMessages)
{
tLMessage = difference as TL.Message;
if(tLMessage != null && tLMessage.peer_id.ID == peerBot.ID )
{
if (!(tLMessage.reply_markup is ReplyMarkup replyMarkup)) continue;
TL.ReplyInlineMarkup replyInlineMarkup = (ReplyInlineMarkup)replyMarkup;
if (replyInlineMarkup.rows[2].buttons[0].Text == "Check text on Button")
{
***//TODO We want to click on this button!***
}
}
}
}
}
The program communicates with Telegram-Bot. A text message is sent to the bot. The bot responds to the message. The answer contains 3 buttons. Question: How to click on a button programmatically?
Create a Telegram client:
_client = new WTelegram.Client(Config):
_user = await _client.LoginUserIfNeeded();
Finding a bot:
var contacts = await _client.Contacts_Search("@Search_bot", 20);
contacts.users.TryGetValue(1911124859, out peerBot));
Sending a request (message) to the Bot:
var message = await _client.SendMessageAsync(peerBot, "REQUEST");
We get an answer:
var differenceMessages = await _client.Updates_GetDifference(state.pts, state.date, state.qts);
We understand the answer. We find a button.
How to send a message to the Bot that we clicked on the button?
TL.Message tLMessage = null;
if (differenceMessages != null)
{
if(differenceMessages.NewMessages != null)
{
foreach (var difference in differenceMessages.NewMessages)
{
tLMessage = difference as TL.Message;
if(tLMessage != null && tLMessage.peer_id.ID == peerBot.ID )
{
if (!(tLMessage.reply_markup is ReplyMarkup replyMarkup)) continue;
TL.ReplyInlineMarkup replyInlineMarkup = (ReplyInlineMarkup)replyMarkup;
if (replyInlineMarkup.rows[2].buttons[0].Text == "Check text on Button")
{
***//TODO We want to click on this button!***
}
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个内联按钮可以是几种类型。
让我们假设您正在谈论“回调”按钮(这将其呼叫发送到bot)。 。
单击该按钮是 noreflow noreferrer“> getBotcallbackanswer 因此,在wtelegramclient命名中)
因此,在您的情况下,您会写下类似的内容:
An inline button can be one of several types.
Let's assume you're talking about a Callback button (that sends its callback to the bot)..
Searching through the full list of API methods available, you would quickly find that the right method to proceed to clicking on that button is messages.getBotCallbackAnswer (so
Messages_GetBotCallbackAnswer
in WTelegramClient naming)Therefore, in your case, you would write something like this: