Reputation: 17372
I've written a bot B
which receives messages from client C1
and forwards it to client C2
, ie 2 people can connect via the gateway Bot
.
I'm using Sleekxmpp, a python client XMPP library for the above purpose.
import logging
from sleekxmpp import ClientXMPP
from sleekxmpp.exceptions import IqError, IqTimeout
class EchoBot(ClientXMPP):
def __init__(self, jid, password):
ClientXMPP.__init__(self, jid, password)
self.add_event_handler("session_start", self.session_start)
self.add_event_handler("message", self.message)
def session_start(self, event):
self.send_presence()
def message(self, msg):
if msg['type'] in ('chat'):
# receive message from the Client1
from, to = message['from'], message['to']
message = message['body']
# send message to Client2.
self.send_message(mto=recipient,
mbody=message,
mtype='chat')
if __name__ == '__main__':
xmpp = EchoBot('[email protected]', 'password')
xmpp.connect()
xmpp.process(block=True)
Now the problem that Client C2 receives the message by the BOT. It should rather receive it from Client C1. For that to happen, I need password of C1 to authorize C1, which I dont have it in the message body neither it is secure to send password in the body.
What is the best approach to create a gateway BOT?
Upvotes: 2
Views: 529
Reputation: 57
Yes, you can set a bot as a gateway for C1 to C2 by setting mfrom = C1 in send_message() method
Upvotes: 1