import slixmpp import toml class SendMsgBot(slixmpp.ClientXMPP): def __init__(self, jid, password, recipient, message): super().__init__(jid, password) self.recipient = recipient self.msg = message self.add_event_handler("session_start", self.start) def start(self, event): self.send_presence() self.get_roster() self.send_message(mto=self.recipient, mbody=self.msg, mtype='chat') self.disconnect() def send_xmpp(event_summary, next_alert, next_event, config): with open('config.toml', 'r') as f: config = toml.load(f) jid = config["xmpp"]["jid"] password = config["xmpp"]["password"] # replace with your password recipient = config["xmpp"]["recipient"] message = """\ Hi, This is an alert for the event named '{}' which will occur on {}. This event will start in '{}' """.format(event_summary, next_event, next_alert) bot = SendMsgBot(jid, password, recipient, message) bot.register_plugin('xep_0030') # Service Discovery bot.register_plugin('xep_0199') # XMPP Ping bot.connect() bot.process(forever=False) return print("Message sent via XMPP")