I'm currently developing a bot for telegram using the Python API and I'm trying to use deep linking to have command parameters running when the user presses the Start button.
For example, my link is http://t.me/mybot?start=parameter
How can I process the parameter that was entered ?
Lots of thanks! :)
You need to set up a webhook for incoming messages to receive such updates. Telegram notifies you automatically when somebody clicks a link like http://t.me/mybot?start=parameter. This is webhook documentation:
https://core.telegram.org/bots/api#setwebhook
Check Telegram deep linking documentation (https://core.telegram.org/bots#deep-linking) for an example.
Use, context.update.startPayload to get the pay load data.
Related
I have been making AI art recently using Midjourney and am aiming to organize all the creations I have made. I have the paid subscription that allows me to message the Midjourney Discord bot directly, so all of my images are in that conversation thread with the bot. My goal is to read each message and download the associated image with it as to catalog the different images. I would be using Python to do so since I have made a discord bot in the past.
I wanted to see if anyone has any thoughts as to how to go about retrieving this data. Once I have a way to access the direct messages I can take it from there -- it is the initial step of how to bring the messages into my script that has me stumped.
My goal is to make a Telegram Bot using Python that does the following:
The user types a command
The bot explains what the user should type next.
The user types certain information
I use that info to fetch a value in a python dictionary.
The bot replies with that info
I have already created the bot and set the command. The problem is that I don't know how to keep the bot "listening" . I have looked up in the docs but I have only found getUpdates, which gets the user's responses but only when you hit run.
res=requests.get(url=f"https://api.telegram.org/bot{bot_token}/getUpdates")
I would like to set a webhook, and I know there is a method for this but I'm not shure about how this works.
When you are a PHP programmer, setting the webhook through a URL and using setWebhook would do the trick and telegram will send the result to this link whenever a user sends an update to the bot. But, Python programmers have to use a different approach, I think. The main, and while, the easiest approach to make the bot listen permanently to the request is to python-telegram-bot module.
There are a few links that can help to build your first pythonic bot that can respond to users' updates.:
Python-Telegram-Bot Repository, which is the repository of the module.
A few examples of bots created using this module, can give you insight into the process of creating your first bot.
A conversation bot
i'm developing a python telegram bot and i have a script that is always running (for receiving new command from telegram) and i want the bot to send messages when the user perform a action in a website.
example: the user start the bot, the bot send a link to perform an action in the website (like login to the user's account and connect the telegram id with the user id) and then send a confirmation message on telegram that all's good.
my problem is how i can tell the python script that the action in the browser is done? for now i'm constantly query a database but my solution is pretty dumb because if the user don't perform any action the query can go forever.
any suggestion how to do it correctly?
thx <3
I see two viable solutions here:
Send the message directly from the website. While only one process is allowed to fetch updates at a time, you can make other requests from as many servers as you like. Depending on how your website works, you can make a plain HTTP request to the Bot API or use an API wrapper like python-telegram-bot or a wrapper in a different language to make the request. e.g. if you're running a php-based website, you could use a php API wrapper.
If for some reason 1. is not an option for you, you can try to inform your running process about the user login. the PTB FAQ have an entry that should help you get started. If your website & bot are running on the same server, it might be possible to make the update_queue directly available to the website process. If not, you can try to set up a webhook for your bot and post an update to the webhook that you then enqueue into the update_queue
Approach 1. has the downside that you don't have all the bot logic in one place, but it should be by far easier to implement than 2.
Disclaimer: I'm currently the maintainer of python-telegram-bot
First post on here. Im working on an application in python using the twilio voice api. Id need to be able to create twiml xml data based on user messages. Hence twiml creation and hosting programmatically on the fly. Is there anyone here that can point me in the right direction. For all i know twilml bin doesnt allow that. Thank you
Twilio developer evangelist here.
You are right that TwiML Bins don't allow to generate dynamic responses (outside of some light templating). However, you are building with Python, so you can build a web application that responds to Twilio webhooks with dynamically generated TwiML.
I'd recommend working through this tutorial on receiving and responding to incoming SMS messages in Python to understand how the process works and how to use the Twilio Python library to generate dynamic TwiML.
I'm using a python script that monitors a website and sends me messages on Facebook if there is any specific updates.
I have tried a module which called 'fbchat', so simple and so easy, but the problem is that I'm using real Facebook accounts and somehow Facebook detected that it's a bot and banned that profile, even if I have made random pauses in my code.
I know that I can do make those notifications through emails, but for me Facebook messages are better... Any ideas about how can I make it possible (maybe through bots!!)?
Thank you!
First take a look at which parameters(headers and payloads) the POST method takes(using network tools in google chrome for example), and try again with as many parameters as possible, while also using a session so cookies are enabled as well.
Different websites use different methods of detecting bots, and you'll just have to test and see what works.
P.S: take a look at this answer for more info.
Multiple Accounts are not allowed on Facebook, and there is no (allowed) way to send messages between users. You can only send messages from Pages to Users, and only if the User started the conversation. You can find more information about that in the docs: https://developers.facebook.com/docs/messenger-platform/