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

柔情痞子 提交于 2019-12-13 12:23:28

问题


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?


回答1:


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.




回答2:


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!




回答3:


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.



来源:https://stackoverflow.com/questions/46101394/how-can-i-join-two-users-in-a-telegram-chat-bot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!