如何在电报聊天机器人中加入两个用户? [英] how can i join two users in a telegram chat bot?

查看:213
本文介绍了如何在电报聊天机器人中加入两个用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将使用 Python 3 创建一个电报机器人,它是一个随机聊天机器人.由于我是电报机器人的新手,所以我不知道如何在聊天机器人中加入两个不同的人.有为此提供的指南吗?

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?

推荐答案

您需要创建一个以chatID作为主列的数据库.和另一列作为合作伙伴.存储他/她的聊天伙伴chatID. 现在,当用户向您的机器人发送消息时,您只需要检查该用户的数据库并将该消息发送给她的聊天伙伴即可. 聊天完成后,您应该清空两个用户的合作伙伴字段.

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.

对于领料部分.当用户要查找新伙伴时,请从数据库中选择一个随机行,其中partnerChatID为Null并将其设置为第一个用户ID,反之亦然.

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.

这篇关于如何在电报聊天机器人中加入两个用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆