#!/usr/bin/python3 # test.py # # Usage: # Install mesibo python package from https://github.com/mesibo/python # Create an application at https://mesibo.com/console # Create a user # Obtain the token and app id for the user and set it # Run the script python3 test.py # Send a message from console to the user. It should be received and printed by your script # Press Ctrl+Z to stop the script # # Refer to https://mesibo.com/documentation/tutorials/first-app/python/ MESIBO_AUTH_TOKEN = "xxxx" MESIBO_APP_ID = "xxxx" from mesibo import Mesibo from mesibo import MesiboNotify class MesiboListener(MesiboNotify): def on_connectionstatus(self, status): """A status = 1 means the listener successfully connected to the Mesibo server """ print(f"## Connection status: {status}") return 0 def on_message(self, msg_params, data, datalen): """Invoked on receiving a new message or reading database messages """ print(f"## Received message from {msg_params['peer']}: {data} of len {datalen}") print(msg_params) print("Message: ", data[: datalen].decode('utf-8')) return 0 def on_messagestatus(self, msg_params): """Invoked when the status of an outgoing or sent message is changed. Statuses can be sent, delivered, or read """ #print(f"## Outgoing msg. To: {msg_params['peer']}, Status: {msg_params['status']}") return 0 def send_text_message(to,message): #api is the Mesibo Python API instance. #Make sure the instance is initialised before you call API functions p = {} p['peer'] = to data = message pymesibo.send_message(p, pymesibo.random(),data) #Initialisation code #Create a Mesibo Instance pymesibo = Mesibo() #Set Listener pymesibo.set_listener(MesiboListener) #Set your AUTH_TOKEN obtained from the Mesibo Console pymesibo.set_accesstoken(MESIBO_AUTH_TOKEN) pymesibo.set_database("mesibo.db") #Set APP_ID which you used to create AUTH_TOKEN pymesibo.set_appname(MESIBO_APP_ID) #Start mesibo pymesibo.start() pymesibo.wait()