how can i join two users in a telegram chat bot? - python

I am going to make a telegram bot in Python 3 which is a random chat bot. As I am new in telegram bots, I don't know how to join two different people in a chat bot. Is there a guide available for this?

If I understood the question, this isn't really about the code but the idea behind it, right?
My way would be:
Someone start the bot (ill call it 'current user' from now on), you get the userID of the new user and store it somewhere (a json file will do the trick)
The current user wanna talk with some other user so you pull off a random userID from the json file and you store it in some variables that are unique for the current user. You also do the same thing for the receiving user
Any new message from the current user will go through the bot and will be replied to the receving user
Quick tip: Use a python wrapper of the Telegram Bots Api, my suggestion would be python telegram bot. Its really good and offers some really neat features to help you (for example you can set user-specific data with pass_user_data). Feel free to check it out!

You need to make a database with chatID as primary column. and another column as partner. which stores his/her chat partner chatID.
now when a user sends a message to you bot you just need to check the database for that user and send the message to her chat partner.
after the chat is done you should empty partner fields of both users.
And for the picking part. when a user wants to find a new partner, choose a random row from your database WHERE partnerChatID is Null and set them to first users ID and vise versa.

I am not sure to understand your question, can you give us what you pretend to do more explained?
You have a few options, creating a group and adding the bot to it.
In private chat you only can talk with a single user at a time.

Related

how to make two people communicate through the bot

I can’t figure out how to make two people communicate through the bot? That is, user1 >message> bot>message>user2 It turns out that the bot acts as an intermediary, passing messages from one user to another
I was thinking of making a database with a user ID, and if a person clicks on the "find a friend" button, the status of his ID = True And if 2 people with the True status, then they can communicate with each other, but there are no further thoughts at all .... Please help((
Remember, the Telegram bot will never be able to write to the user, if he himself did not activate this bot before.
So. Your idea can be implemented as follows. The user enters the bot and is offered a choice (two buttons). The first button is "connect with a random user", and the second is "connect by id".
The first option: you accept a message from that user and duplicate it to another (and vice versa).
The second option: if the user enters the correct id of another user, he receives a notification about a successful connection, and then everything is the same as in the first option. If the id is incorrect - an error message.
For navigation I would use InlineKeyboard (or alternatively ReplyKeyboard). It turns out that the bot will be an intermediary between users.
Disadvantages for users: you (an outsider) will be able to save all correspondence and view them. View complete information about the user's account.
Benefits for users: They will be completely anonymous to each other.
I could say more about this, but I don't quite understand the point of creating a bot for such things

Telegram Bot - Persist Pickle Context across all Users in a Group Chat

I set out to create a Telegram bot that tracks 'upvote' like functionality in a Group Chat. To try to do this, I adapted the persistentconversationbot.py code from the python-telegram-bot package. I got the bot running and managed to deploy it on to Heroku.
Once I invited the bot into a private group chat, I noticed that this approach is only remembering conversations with specific users. I'd like to have the bot remember conversations it has had with all users in a group chat. Would any of you happen to know how I can do this?
Thank you!
Please see this explanation on the per_* parameters of ConversationHandler. Note that this is independent of whether your bot uses persistence or not.

discord.py: Hide messages from all other users, but the #mention user

I'm developing a matchmaking bot for discord. I read through the documentation and looked through stack exchange, I can't find relevant information on this. I'm trying to eliminate clutter and make it easier for a users to accept and decline a matchmaking request. The bot would listen for a "!match #user" and handle the event. I only want the #user to see and accept it and the user that sent the message to see it (obviously). Right now, I believe it's not possible unless it assigns a secret role and deletes these roles after they are finished; this wouldn't be ideal though. Any information or forward to a post, that would help tremendously. Thanks in advance.
You can not currently hide messages for any specific user/role.
You can try 2 approaches:
Send Message in User DMs
Make a channel and set it permissions for a specific role and assign that role to the user

Send a message to all users when the bot wake up

I've started tinkering with python recently and I'm on my way to create my very first telegram bot mainly for managing my Raspberry Pi and a few things connected to it. The bot is done but I would like to send a message to all the users that have already interacted with the bot when it starts, basically saying something like "I'm ready!", but I haven't been able to find any information about it.
Is there any specific method in the API already done to do this? Or should I create another file to store the chat_id from all the users and read it with python?
Thank you all for your help!! Regards!
You should have a Database that stores Chat-id(s) of Clients that interact with your bot.
If you're able to put them into a list, then the job is half done.
All you need to do is to create a "for loop", and send message to all the ID(s) in the list.
Example:
message = "Good morning"
chats =[1234447488,3748838477,4748848578,7463638488]
for chat in chats:
bot.send_message(chat_id=chat,text= "message")
In case of of clients that have deleted your bot, you may experience an error. You can catch that with try and except.
Is there any specific method in the API already done to do this?
No, there's no such method.
Or should I create another file to store the chat_id from all the users and read it with python?
Yes, you should handle it yourself. Usually user ids and another information about User <-> Bot interaction is stored in a database on a server, because it's easier for maintaining and searching.
So if you want to send a plain text message to your users in a file, you should call SendMessage method of telegram bot API for every user in your file.
You should save users in database or file.After that use for to send_message one by one to all users that you have in database or file.
Yes you should create another file or use a database to store the chat_id of all the users you interact with. You can check Telegram Bots API to see all the available commands. if there is no such command then there probably won't be any command in the wrapper you are using for python either.

fb messenger bot: bot ask user for answers

Currently, I've a Python code. That process the incomming message from a Facebook messenger User. But this is a pasive chat against the chat bot. I'd like to do the following.
User: Pay
Bot: Please type the username of the person you want to pay.
User: eddwinpaz
Bot: Please type the amount you want to send.
User: 100.00
Bot: Are you sure you want to send 100.00 to Eddwinpaz?
Some how if the user in this conversation does not answers on the exact order the app wont be able to do the payment. There is a way to get the previous text and see if its answering in the correct order. Or give some logic in order to store in a session_array[sender_id,username,amount] and after I send the user a Button(Yes,No) I can actually perform the payment.
Because I need to store on the server the values regarding a question. Other example is.
Bot: what is your email?
User: myemail#gmail.com
Bot: your email has been saved!
Facebook does not provide a way to do this, it is up to you to handle state in your code.
This is what bot frameworks are for! Conversation management, aka state management. It comes down to either holding the past messages in a db to have state, or persisting "conversations" in memory.
There is no "right" way to do this (in my opinion) and if you want a simple answer to your question it is: use a bot framework instead of writing this functionality from scratch.

Categories

Resources