How to make a Python telegram bot wait for user input? - python-3.x

Example: I send /weather to a bot and he asked me city. How to make him wait to reply?

ConversationHandler can be used to achieve the purpose. Python-telegram-bot conversationbot2.py example gives a good reference.

You can use the InlineKeyboardButton for that. It pops up a button for the user to press on. You can 'wait' for the user to input the data that way

Related

Enter for message telegram bot

Currently, I am developing telegram bot to send message to all member in group chat.
My difficulty right now I cannot make a message with enter.
I already tried adding \n however it wont worked.
this is what I want for example.
message:
Good morning,
Have good day.
when the message need to have enter it cannot send with enter. the result will be like this.
Good morning,/n/n Have good day.
does anyone know how telegram read enter which can be used in python code.
Ok, to send multiline messages, you can use the multiline strings like this:
bot.send_message('chat-id', """
Good morning,
Have good day.
""")
and enable the markup also, so that it dose not interfere the empty lines.

in discord.py, How do I make a bot command that reaches multiple replies, saving the data into a variable?

I want to be able to create a command that lets me get a response from a user which will then be saved as a variable, that'll be saved into another file for safekeeping.
(an example would be making a character sheet in direct messages, where you need to input multiple messages to get the desired outcome.)
I'm stuck and need help with finding a reliable way to make replies and to be able to stock the ones sent by the user. Thank you in advance.
I am not sure, but i think what you are looking for is wait_for
There are two examples in the discord.py docs, the first example covers wait_for message. It can be found on this url: https://discordpy.readthedocs.io/en/latest/api.html?highlight=wait_for#discord.Client.wait_for

Is it possible to show the title and link of a song that started from queue while using lavalink.py

I am making a disord.py music bot using lavalink.py for music streaming. Right now whenever you have a queue of songs it will play through them all, but in order to see what song is currently playing you need to use a command for it. I want the discord bot to send an embed with the song name and link when the next song in the queue starts. I used to use youtube-dl for the music function but it has since stopped working. I'm not sure if I need to use the StartTrackEvent and if I do, I'm not sure how to actually implement it to where it will send a message in the discord channel. Also, my music code is in a cog if that makes much of a difference.
(I'm new to SO, excuse me if my answer isn't super great)
You would not need an event to do this (assuming you're using the commands extension.) You could make your queue command, and use AudioTrack.title and AudioTrack.identifier to get the track and Youtube identifier. Using the identifier you could link to the track with https://youtube.com/watch?v=<identifier>. An example of this would be:
#commands.command(name="current",description="Shows the current playing song.",usage="current",aliases=['np','nowplaying'])
async def current(self,ctx):
player = self.bot.lavalink.player_manager.get(ctx.guild.id)
embed=discord.Embed(title=player.current.title,url=f"https://youtube.com/watch?v={player.current.identifier}")
await ctx.send(embed=embed)
This would return an embed that contains the title of the current track, and a link to the site in the title.

Show upper-part of adaptive card

I have this very long "form" using adaptive card. Using CardFactory, the bot framework, based on my understanding, can render the card and my bot can display it for my user to fill in the necessary details.
The end of my form (in which I'll use instead of the word adaptive card), has a submit button for user to click whenever all fields are filled in. And while everything works the way I want it to be, its not really user friendly in a sense that what user sees after showing the form is the bottom part of it. User has to scroll for a bit to go up and see the first part of the form.
My question is: Is there anyway I could help user experience by showing the upper-part/top most part of the form? Is that possible in bot framework?
Like if the bot sends successive messages, does the framework allows to show the first messages first, before the last part. THANK YOU!
PS. I use NodeJS for my bot framework, read the documentation but can't find one that dwells deeply about adaptive cards.
Please see images below:
How do I make the first framework to show the first image before the end part which is in the second image.
Have you looked at the "ShowCard" action? It basically lets you collapse part of your card, and only open it when a user clicks on a button. That way you could possibly group your card into sections and show each one at a time. See here for more.
Another option in future is the new ToggleVisibility action in AdaptiveCards 1.2, but it's only if your client supports 1.2. (e.g. it's only available in Developer Preview for Teams right now (so very likely coming in future, but not available at the moment))

telegram bot prefill text for user to edit

Telegram bot sends me a message with a text snippet, which I want to edit, and send back to the bot for further processing.
Copy and paste takes time. Typing message anew takes time.
Ideally I'd like to press an inline button "Edit" on the bot's message and get the message text appear in my reply input box for editing.(A message id attached to my reply somehow would be a plus).
I tried to use deep linking with parameters other than /start*, but that doesn't seem to work.
Can I use bot API (or any other telegram API) to have text ready for editing in my input box?
It's impossible in official apps yet. Your question is about working with drafts - there are no methods in both API to create them or clear.
Nevertheless, you could fork any official app stored on GiHub and implement what you need if you would prefer a hard way, but compared to that copy/past solution seems much more easier, isn't it?
UPD
I can offer to you a new idea how to solve your problem - hope it will be helpful.
This is about switch_inline_query_current_chat field of InlineKeyboardButton. Just attach an inline button to messages you need to edit. Set a text for this field gotten from recieved message and after pressing you will get this text to your input area. All seems good, but you will take bot's username before the text also.

Resources