9
9
ngrok (https://ngrok.com/) can be used to tunnel traffic back to your server
10
10
if your machine sits behind a firewall.
11
11
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.
14
14
15
- Additional Spark webhook details can be found here:
15
+ Additional Webex Teams webhook details can be found here:
16
16
https://developer.webex.com/webhooks-explained.html
17
17
18
18
A bot must be created and pointed to this server in the My Apps section of
75
75
# Create the web application instance
76
76
flask_app = Flask (__name__ )
77
77
# Create the Webex Teams API connection object
78
- spark_api = WebexTeamsAPI ()
78
+ api = WebexTeamsAPI ()
79
79
80
80
81
81
# Helper functions
@@ -93,16 +93,16 @@ def get_catfact():
93
93
94
94
95
95
# 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."""
100
100
if request .method == 'GET' :
101
101
return ("""<!DOCTYPE html>
102
102
<html lang="en">
103
103
<head>
104
104
<meta charset="UTF-8">
105
- <title>Spark Bot served via Flask</title>
105
+ <title>Webex Teams Bot served via Flask</title>
106
106
</head>
107
107
<body>
108
108
<p>
@@ -128,11 +128,11 @@ def sparkwebhook():
128
128
# Create a Webhook object from the JSON data
129
129
webhook_obj = Webhook (json_data )
130
130
# Get the room details
131
- room = spark_api .rooms .get (webhook_obj .data .roomId )
131
+ room = api .rooms .get (webhook_obj .data .roomId )
132
132
# Get the message details
133
- message = spark_api .messages .get (webhook_obj .data .id )
133
+ message = api .messages .get (webhook_obj .data .id )
134
134
# Get the sender's details
135
- person = spark_api .people .get (message .personId )
135
+ person = api .people .get (message .personId )
136
136
137
137
print ("NEW MESSAGE IN ROOM '{}'" .format (room .title ))
138
138
print ("FROM '{}'" .format (person .displayName ))
@@ -141,7 +141,7 @@ def sparkwebhook():
141
141
# This is a VERY IMPORTANT loop prevention control step.
142
142
# If you respond to all messages... You will respond to the messages
143
143
# that the bot posts and thereby create a loop condition.
144
- me = spark_api .people .me ()
144
+ me = api .people .me ()
145
145
if message .personId == me .id :
146
146
# Message was sent by me (bot); do not respond.
147
147
return 'OK'
@@ -154,7 +154,7 @@ def sparkwebhook():
154
154
cat_fact = get_catfact ()
155
155
print ("SENDING CAT FACT '{}'" .format (cat_fact ))
156
156
# 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 )
158
158
return 'OK'
159
159
160
160
0 commit comments