99ngrok (https://ngrok.com/) can be used to tunnel traffic back to your server
1010if your machine sits behind a firewall.
1111
12- You must create a Spark webhook that points to the URL where this script is
13- hosted. You can do this via the WebexTeamsAPI.webhooks.create() method.
12+ You must create a Webex Teams webhook that points to the URL where this script
13+ is hosted. You can do this via the WebexTeamsAPI.webhooks.create() method.
1414
15- Additional Spark webhook details can be found here:
15+ Additional Webex Teams webhook details can be found here:
1616https://developer.webex.com/webhooks-explained.html
1717
1818A bot must be created and pointed to this server in the My Apps section of
7575# Create the web application instance
7676flask_app = Flask (__name__ )
7777# Create the Webex Teams API connection object
78- spark_api = WebexTeamsAPI ()
78+ api = WebexTeamsAPI ()
7979
8080
8181# Helper functions
@@ -93,16 +93,16 @@ def get_catfact():
9393
9494
9595# Core bot functionality
96- # Your Spark webhook should point to http://<serverip>:5000/sparkwebhook
97- @flask_app .route ('/sparkwebhook ' , methods = ['GET' , 'POST' ])
98- def sparkwebhook ():
99- """Processes incoming requests to the '/sparkwebhook ' URI."""
96+ # Your Webex Teams webhook should point to http://<serverip>:5000/events
97+ @flask_app .route ('/events ' , methods = ['GET' , 'POST' ])
98+ def webex_teams_webhook_events ():
99+ """Processes incoming requests to the '/events ' URI."""
100100 if request .method == 'GET' :
101101 return ("""<!DOCTYPE html>
102102 <html lang="en">
103103 <head>
104104 <meta charset="UTF-8">
105- <title>Spark Bot served via Flask</title>
105+ <title>Webex Teams Bot served via Flask</title>
106106 </head>
107107 <body>
108108 <p>
@@ -128,11 +128,11 @@ def sparkwebhook():
128128 # Create a Webhook object from the JSON data
129129 webhook_obj = Webhook (json_data )
130130 # Get the room details
131- room = spark_api .rooms .get (webhook_obj .data .roomId )
131+ room = api .rooms .get (webhook_obj .data .roomId )
132132 # Get the message details
133- message = spark_api .messages .get (webhook_obj .data .id )
133+ message = api .messages .get (webhook_obj .data .id )
134134 # Get the sender's details
135- person = spark_api .people .get (message .personId )
135+ person = api .people .get (message .personId )
136136
137137 print ("NEW MESSAGE IN ROOM '{}'" .format (room .title ))
138138 print ("FROM '{}'" .format (person .displayName ))
@@ -141,7 +141,7 @@ def sparkwebhook():
141141 # This is a VERY IMPORTANT loop prevention control step.
142142 # If you respond to all messages... You will respond to the messages
143143 # that the bot posts and thereby create a loop condition.
144- me = spark_api .people .me ()
144+ me = api .people .me ()
145145 if message .personId == me .id :
146146 # Message was sent by me (bot); do not respond.
147147 return 'OK'
@@ -154,7 +154,7 @@ def sparkwebhook():
154154 cat_fact = get_catfact ()
155155 print ("SENDING CAT FACT '{}'" .format (cat_fact ))
156156 # Post the fact to the room where the request was received
157- spark_api .messages .create (room .id , text = cat_fact )
157+ api .messages .create (room .id , text = cat_fact )
158158 return 'OK'
159159
160160
0 commit comments