#!/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()
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}