telegram bot - Bot api, how i can get last message or chat history? -
i want implement functional user send me message , reply him (bot) latest message chat history.
as can see in telegram bot api documentation can use sendmessage
send message user.
when receive message, chat
or from
parameter in json (depends if want answer person when it's group chat or not). can use id
parameter of chat
or from
send message.
so first parameter sendmessage chat_id=message.chat.id
you don't need parse_mode
, disable_web_page_preview
, reply_markup
example.
as want reply message of user may want set reply_to_message_id
id of received message.
reply_to_message_id = message.message_id
last not least, want set text
parameter. if understand correctly, program send last received message.text
user.
so want is, message, save it.
message oldmessage = message
and when send message user use old messages text
property text.
text = oldmessage.text
alright sum here pseudocode of function happen receive message:
message oldmessage = null; public void newmessage(message message){ int chat_id = message.chat.id; int reply_to_message_id = message.message_id; string text = "there no old message"; //fallback value if(oldmessage != null){ text = oldmessage.text; } //send message in example has 3 parameters, , ignores //not used ones sendmessage(chat_id,text,reply_to_message_id); oldmessage = message; //store received message future answering }
as store whole message in oldmessage
set text send this:
string text = oldmessage.from.first_name+": "+oldmessage.text;
Comments
Post a Comment