-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfirst-app.py
More file actions
122 lines (97 loc) · 3.52 KB
/
Copy pathfirst-app.py
File metadata and controls
122 lines (97 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/python3
# first-app.py
#
# Usage:
# Install mesibo python package from https://github.com/mesibo/python
# Create an application at https://mesibo.com/console
# Create a user and Obtain the token and app id for the user and set it
# Run the script
#
# $ python3 first-app.py
#
# Send a message from console to the user. It should be received and printed by your python script
# Use Ctrl+Z or pkill to stop the script
#
# Refer to https://mesibo.com/documentation/tutorials/get-started/ to learn more
import mesibo
from mesibo import MesiboListener
class PyMesiboListener(MesiboListener):
def Mesibo_onConnectionStatus(self, status):
"""A status = mesibo.MESIBO_STATUS_ONLINE means the listener
successfully connected to the mesibo server
"""
print("## Mesibo_onConnectionStatus: ", status)
if(status == mesibo.MESIBO_STATUS_AUTHFAIL):
exit(1)
return 0
def Mesibo_onMessage(self, msg):
"""Invoked on receiving a new message
or reading database messages
msg: Message Object
"""
try:
if(msg.isRichMessage()):
print("\n ## message:", msg.message)
print("\n ## title:", msg.title)
print("\n ## subtitle:", msg.subtitle)
print("\n ## path:", msg.file.path)
print("\n ## url:", msg.file.url)
#print("\n ## tn:", msg.file.thumbnail)
else:
print("\n ## Received data:", msg.data)
except:
pass
print("\n ## Mesibo_onMessage: ", msg)
return 0
def Mesibo_onMessageUpdate(self, msg):
"""Invoked on receiving a message update
"""
print("\n ## Mesibo_onMessageUpdate: ", msg)
return 0
def Mesibo_onMessageStatus(self, msg):
"""Invoked when the status
of an outgoing or sent message is changed.
"""
print("## Mesibo_onMessageStatus", msg)
return 0
def Mesibo_onPresence(self, msg):
print("## Mesibo_onPresence", msg)
return 0
# Get access token and app id by creating a mesibo user
# See https://mesibo.com/documentation/tutorials/get-started/
ACCESS_TOKEN = "<use your user token>"
APP_ID = "com.mesibo.python"
# Create a Mesibo Instance
api = mesibo.getInstance()
# if you are sending or receiving binary/signalling data, set the format. By default, mesibo
# auto detects and sets to Unicode string or bytes[]
# You can override it by setting mesibo.MESIBO_READAS_BYTES or mesibo.MESIBO_READAS_UNICODE
# mesibo.readDataAs(mesibo.MESIBO_READAS_AUTO)
# Enable or disable End-to-end-encryption
e2ee = api.e2ee();
e2ee.enable(1)
# Set Listener
listener = PyMesiboListener()
api.addListener(listener)
# Set your AUTH_TOKEN obtained while creating the user
if(mesibo.MESIBO_RESULT_FAIL == api.setAccessToken(ACCESS_TOKEN)):
print("===> Invalid ACCESS_TOKEN: ", ACCESS_TOKEN)
print("See https://mesibo.com/documentation/tutorials/get-started/")
exit(1)
# Set APP_ID which you used to create AUTH_TOKEN
api.setAppName(APP_ID)
# Set the name of the database
api.setDatabase("mesibo", 0)
# Start mesibo,
api.start()
input("Press Enter to to send a message...\n")
msg = api.newMessage("destination")
msg.title = "Hello"
msg.message = "Hello message"
#msg.setContent("pic1.jpg")
#msg.setContent("https://mesibo.com")
msg.send()
#e2ee.getPublicCertificate("/root/pycert.cert")
#print("fingerPrint: " + e2ee.getFingerprint("destination"))
#Wait for the application to exit
api.wait()