9

I'm building a Telegram bot, in which the user sends messages, which are later posted to another website. The bot can often give the user a suggestion of what to write, but the user must have a chance to edit this suggestion before actually posting it.

I could send this suggestion as a message from the bot to the user, and the user could copy and paste it to the message input box. However, copying and pasting is a bit cumbersome, especially on a touch device. It would be much more convenient if I could put the text directly into the editing box.

Is it possible?

I am now using the Tgfancy library, but I don't mind using another library if it has this feature.

Thank you!

Amir E. Aharoni
  • 1,308
  • 2
  • 13
  • 25

3 Answers3

6

switch_inline_query_current_chat of InlineKeyboardButton is what is needed to pre-fill the text area with your inline query parameter

isaacalan
  • 73
  • 1
  • 8
3

As @isaacalan mentioned yes, we can, but not completely custom. By default the bot's name is inserted first, plus any user's text. In my case @enpodbot is prefixed by default, then /audio 1 is my custom text. Also a user can type more.

a simple shot

enter image description here

the code

197    if( number === 'xxx' ){
198         bot.telegram.sendMessage( user_id, 'please click below button and give it a number: 1 to 365' ,
199         {
200             parse_mode: 'HTML',
201             reply_markup: {
202                 inline_keyboard: [
203                     [
204                         {  text: 'Let me help you ...' , switch_inline_query_current_chat: '/audio 1'  }
205                     ]
206                 ]
207             }
208 
209         });
210         return 0;
211     }

reference

https://core.telegram.org/bots/api#sendmessage
and
https://core.telegram.org/bots/api#inlinekeyboardmarkup

Shakiba Moshiri
  • 21,040
  • 2
  • 34
  • 44
2

telegram has released its bot api 3.0 on May 18, 2017, and there is no api to access or manipulate the content of user's chatbox.

i don't know what type of suggestions you want to provide and what type of texts you want to accept. but there are 2 things you may try:

  1. if your users will send some predefined short messages, you can define some commands for them. (e.g. /hello, /howareyou, ...). telegram itself automatically suggests commands to users of a bot.

  2. you may use inlineKeyboardButtons to show the suggested texts.note that inlineKeyboardButtons can be updated without sending an extra message to user. but how? user can send his first word to bot, and bot will send a reply post with inlineKeyboardButtons containing suggested texts, and user can choose the desired completion text(by tapping on the chosen option), then app updates the post and its keyboards showing the new options. note that your posts should have an extra inlineKeboard button to be used as the sign of the ending of the text completion process.

tashakori
  • 2,331
  • 1
  • 22
  • 29
  • 1
    The suggestions I want are Translation Memory ( https://en.wikipedia.org/wiki/Translation_memory ). The whole point of Translation Memory is that some text is pre-filled, but it almost always must be edited by a human before submitting. I could make inlineKeyboardButtons, but they could send a full string without human editing. – Amir E. Aharoni Jun 26 '17 at 16:04