1010if your machine sits behind a firewall.
1111
1212You must create a Spark webhook that points to the URL where this script is
13- hosted. You can do this via the CiscoSparkAPI .webhooks.create() method.
13+ hosted. You can do this via the WebexTeamsAPI .webhooks.create() method.
1414
1515Additional Spark webhook details can be found here:
16- https://developer.ciscospark .com/webhooks-explained.html
16+ https://developer.webex .com/webhooks-explained.html
1717
1818A bot must be created and pointed to this server in the My Apps section of
19- https://developer.ciscospark .com. The bot's Access Token should be added as a
20- 'SPARK_ACCESS_TOKEN ' environment variable on the web server hosting this
19+ https://developer.webex .com. The bot's Access Token should be added as a
20+ 'WEBEX_TEAMS_ACCESS_TOKEN ' environment variable on the web server hosting this
2121script.
2222
2323This script supports Python versions 2 and 3.
2424
25+ Copyright (c) 2016-2018 Cisco and/or its affiliates.
26+
27+ Permission is hereby granted, free of charge, to any person obtaining a copy
28+ of this software and associated documentation files (the "Software"), to deal
29+ in the Software without restriction, including without limitation the rights
30+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
31+ copies of the Software, and to permit persons to whom the Software is
32+ furnished to do so, subject to the following conditions:
33+
34+ The above copyright notice and this permission notice shall be included in all
35+ copies or substantial portions of the Software.
36+
37+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
40+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
41+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
42+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
43+ SOFTWARE.
2544"""
2645
2746
5372
5473
5574# Initialize the environment
56- flask_app = Flask (__name__ ) # Create the web application instance
57- spark_api = WebexTeamsAPI () # Create the Webex Teams API connection object
75+ # Create the web application instance
76+ flask_app = Flask (__name__ )
77+ # Create the Webex Teams API connection object
78+ spark_api = WebexTeamsAPI ()
5879
5980
6081# Helper functions
@@ -72,7 +93,8 @@ def get_catfact():
7293
7394
7495# Core bot functionality
75- @flask_app .route ('/sparkwebhook' , methods = ['GET' , 'POST' ]) # Your Spark webhook should point to http://<serverip>:5000/sparkwebhook
96+ # Your Spark webhook should point to http://<serverip>:5000/sparkwebhook
97+ @flask_app .route ('/sparkwebhook' , methods = ['GET' , 'POST' ])
7698def sparkwebhook ():
7799 """Processes incoming requests to the '/sparkwebhook' URI."""
78100 if request .method == 'GET' :
@@ -96,16 +118,21 @@ def sparkwebhook():
96118 elif request .method == 'POST' :
97119 """Respond to inbound webhook JSON HTTP POST from Webex Teams."""
98120
99- json_data = request .json # Get the POST data sent from Webex Teams
121+ # Get the POST data sent from Webex Teams
122+ json_data = request .json
100123 print ("\n " )
101124 print ("WEBHOOK POST RECEIVED:" )
102125 print (json_data )
103126 print ("\n " )
104127
105- webhook_obj = Webhook (json_data ) # Create a Webhook object from the JSON data
106- room = spark_api .rooms .get (webhook_obj .data .roomId ) # Get the room details
107- message = spark_api .messages .get (webhook_obj .data .id ) # Get the message details
108- person = spark_api .people .get (message .personId ) # Get the sender's details
128+ # Create a Webhook object from the JSON data
129+ webhook_obj = Webhook (json_data )
130+ # Get the room details
131+ room = spark_api .rooms .get (webhook_obj .data .roomId )
132+ # Get the message details
133+ message = spark_api .messages .get (webhook_obj .data .id )
134+ # Get the sender's details
135+ person = spark_api .people .get (message .personId )
109136
110137 print ("NEW MESSAGE IN ROOM '{}'" .format (room .title ))
111138 print ("FROM '{}'" .format (person .displayName ))
@@ -123,9 +150,11 @@ def sparkwebhook():
123150 # Message was sent by someone else; parse message and respond.
124151 if "/CAT" in message .text :
125152 print ("FOUND '/CAT'" )
126- cat_fact = get_catfact () # Get a cat fact
153+ # Get a cat fact
154+ cat_fact = get_catfact ()
127155 print ("SENDING CAT FACT '{}'" .format (cat_fact ))
128- spark_api .messages .create (room .id , text = cat_fact ) # Post the fact to the room where the request was received
156+ # Post the fact to the room where the request was received
157+ spark_api .messages .create (room .id , text = cat_fact )
129158 return 'OK'
130159
131160
0 commit comments