-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample-app.py
More file actions
62 lines (54 loc) · 2.07 KB
/
example-app.py
File metadata and controls
62 lines (54 loc) · 2.07 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
from flask import Flask, request
import requests
import json
webInterfaceURL = "http://localhost:3000/WickrIO/V1/Apps/CLIENT_API_KEY"
PARAMS = {'Accept': '*/*', 'Content-Type': 'application/json',
'Authorization': 'Basic AUTH_KEY'}
PORT_NUMBER = 8090
app = Flask(__name__) # create the Flask app
def main():
# Configure client to send incoming messages to this apps address
payload = {'callbackurl': 'http://127.0.0.1:8090/callback'}
setMsgRecvCallback = requests.post(webInterfaceURL + "/MsgRecvCallback",
headers=PARAMS,
params=payload)
print(setMsgRecvCallback.content)
print("HELLO")
# Get MsgRecvCallback
getMsgRecvCallback = requests.get(webInterfaceURL + "/MsgRecvCallback",
headers=PARAMS)
print(getMsgRecvCallback.content)
@app.route('/callback', methods=['POST'])
def register():
# Parse incoming message and decide what to do with it
print('New incoming Message:', request.get_json())
command = "/help"
print(sender)
# Other possible properties to extract from incoming messages
# argument = request.get_json()["argument"]
# userEmail = request.get_json()["userEmail"]
# vGroupID = request.get_json()["vgroupid"]
# convoType = request.get_json()["convoType"]
#
# Start coding below and modify the listen function to your needs
#
if command == "/help":
print("command == /help")
reply = "What can I help you with?"
# send 1-to-1 Message
data = {
"message": reply,
"users": [
{"name": sender}
]
}
sendMessage = requests.post(webInterfaceURL + "/Messages",
headers=PARAMS,
data=json.dumps(data))
print(sendMessage.content)
return "OK 200"
if __name__ == "__main__":
main()
app.run(debug=True, port=PORT_NUMBER) # run app in debug mode on port 5000
print("WORLD")