-
Notifications
You must be signed in to change notification settings - Fork 0
/
sparkmessage.py
73 lines (54 loc) · 1.74 KB
/
sparkmessage.py
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
#!/usr/bin/env python
import json
import os
import requests
from flask import Flask
from flask import make_response
from flask import request
# Flask app should start in global layout
app = Flask(__name__)
##
# Authorization token for Spark. Required for working with Spark's API.
#
AUTH = "ZDcxYTdiZjEtZTM4My00ZjAyLTlmN2YtODA2NGFkMWZjZDA4ZjRkZDI5ZDAtZTRh"
##
# Request header for Spark Web API
#
HEADERS = {'Authorization':'Bearer ' + AUTH}
##
# Spark Web API URLs
#
BASE_URL = "https://api.ciscospark.com/v1/"
ROOMS_URL = BASE_URL+"rooms"
MESSAGES_URL = BASE_URL+"messages"
ROOM_ID = "05d3bfaf-3bca-3767-b767-7c00c10e8a1c"
#ROOM_ID = "12a8f8e0-2922-11e7-9841-0b019e058365"
@app.route('/transcription', methods=['POST', 'PATCH'])
def webhook():
req = request.get_json(silent=True, force=True)
print("Request:")
print(json.dumps(req, indent=4))
res = processRequest(req)
res = json.dumps(res, indent=4)
print(res)
r = make_response(res)
r.headers['Content-Type'] = 'application/json'
return r
def processRequest(req):
trascriptedMessage = req.get("result").get("transcription")
status = req.get("result").get("status")
guid = req.get("result").get("guid")
identifier = req.get("result").get("identifier")
response = send_message(ROOM_ID, trascriptedMessage)
json_dump = json.dumps(response)
print(json_dump)
return json_dump
def send_message(room_id, message):
data = { "roomId" : room_id,
"text" : message }
resp = requests.post(MESSAGES_URL,json=data, headers=HEADERS)
return json.loads(resp.text)
if __name__ == '__main__':
port = int(os.getenv('PORT', 5000))
print "Starting app on port %d" % port
app.run(debug=True, port=port, host='0.0.0.0')