Skip to content

Commit f232e1c

Browse files
committed
Spark to Webex Teams name changes
A few final changes.
1 parent 5ca450c commit f232e1c

File tree

6 files changed

+36
-35
lines changed

6 files changed

+36
-35
lines changed

examples/bot-example-flask.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
ngrok (https://ngrok.com/) can be used to tunnel traffic back to your server
1010
if 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:
1616
https://developer.webex.com/webhooks-explained.html
1717
1818
A bot must be created and pointed to this server in the My Apps section of
@@ -75,7 +75,7 @@
7575
# Create the web application instance
7676
flask_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

examples/bot-example-webpy.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
launching the script if desired. ngrok can be used to tunnel traffic back to
88
your server if you don't wish to expose your machine publicly to the Internet.
99
10-
You must create a Spark webhook that points to the URL where this script is
11-
hosted. You can do this via the WebexTeamsAPI.webhooks.create() method.
10+
You must create a Webex Teams webhook that points to the URL where this script
11+
is hosted. You can do this via the WebexTeamsAPI.webhooks.create() method.
1212
13-
Additional Spark webhook details can be found here:
13+
Additional Webex Teams webhook details can be found here:
1414
https://developer.webex.com/webhooks-explained.html
1515
1616
A bot must be created and pointed to this server in the My Apps section of
@@ -72,8 +72,8 @@
7272

7373

7474
# Global variables
75-
# Your Spark webhook should point to http://<serverip>:8080/sparkwebhook
76-
urls = ('/sparkwebhook', 'webhook')
75+
# Your Webex Teams webhook should point to http://<serverip>:8080/events
76+
urls = ('/events', 'webhook')
7777
# Create the web application instance
7878
app = web.application(urls, globals())
7979
# Create the Webex Teams API connection object
@@ -96,7 +96,7 @@ def get_catfact():
9696
class webhook(object):
9797
def POST(self):
9898
"""Respond to inbound webhook JSON HTTP POSTs from Webex Teams."""
99-
# Get the POST data sent from Spark
99+
# Get the POST data sent from Webex Teams
100100
json_data = web.data()
101101
print("\nWEBHOOK POST RECEIVED:")
102102
print(json_data, "\n")

examples/ngrokwebhook.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
# Constants
6969
NGROK_CLIENT_API_BASE_URL = "http://localhost:4040/api"
7070
WEBHOOK_NAME = "ngrok_webhook"
71-
WEBHOOK_URL_SUFFIX = "/sparkwebhook"
71+
WEBHOOK_URL_SUFFIX = "/events"
7272
WEBHOOK_RESOURCE = "messages"
7373
WEBHOOK_EVENT = "created"
7474

@@ -92,18 +92,18 @@ def get_ngrok_public_url():
9292
return tunnel["public_url"]
9393

9494

95-
def delete_webhooks_with_name(spark_api, name):
95+
def delete_webhooks_with_name(api, name):
9696
"""Find a webhook by name."""
97-
for webhook in spark_api.webhooks.list():
97+
for webhook in api.webhooks.list():
9898
if webhook.name == name:
9999
print("Deleting Webhook:", webhook.name, webhook.targetUrl)
100-
spark_api.webhooks.delete(webhook.id)
100+
api.webhooks.delete(webhook.id)
101101

102102

103-
def create_ngrok_webhook(spark_api, ngrok_public_url):
103+
def create_ngrok_webhook(api, ngrok_public_url):
104104
"""Create a Webex Teams webhook pointing to the public ngrok URL."""
105105
print("Creating Webhook...")
106-
webhook = spark_api.webhooks.create(
106+
webhook = api.webhooks.create(
107107
name=WEBHOOK_NAME,
108108
targetUrl=urljoin(ngrok_public_url, WEBHOOK_URL_SUFFIX),
109109
resource=WEBHOOK_RESOURCE,
@@ -116,11 +116,11 @@ def create_ngrok_webhook(spark_api, ngrok_public_url):
116116

117117
def main():
118118
"""Delete previous webhooks. If local ngrok tunnel, create a webhook."""
119-
spark_api = WebexTeamsAPI()
120-
delete_webhooks_with_name(spark_api, name=WEBHOOK_NAME)
119+
api = WebexTeamsAPI()
120+
delete_webhooks_with_name(api, name=WEBHOOK_NAME)
121121
public_url = get_ngrok_public_url()
122122
if public_url is not None:
123-
create_ngrok_webhook(spark_api, public_url)
123+
create_ngrok_webhook(api, public_url)
124124

125125

126126
if __name__ == '__main__':

examples/people.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf-8 -*-
33
""" Script to demonstrate the use of webexteamssdk for the people API
44
5-
The package natively retrieves your Spark access token from the
5+
The package natively retrieves your Webex Teams access token from the
66
WEBEX_TEAMS_ACCESS_TOKEN environment variable. You must have this environment
77
variable set to run this script.
88

examples/simple.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
If one or more rooms with the name of the demo room already exist, it will
77
delete the previously existing rooms.
88
9-
The package natively retrieves your Spark access token from the
9+
The package natively retrieves your Webex Teams access token from the
1010
WEBEX_TEAMS_ACCESS_TOKEN environment variable. You must have this environment
1111
variable set to run this script.
1212
@@ -20,7 +20,8 @@
2020
DEMO_ROOM_NAME = "webexteamssdk Demo Room"
2121
2222
DEMO_MESSAGE = u"Webex Teams rocks! \ud83d\ude0e"
23-
DEMO_FILE_URL = "https://developer.webex.com/images/[email protected]"
23+
DEMO_FILE_URL = \
24+
"https://www.webex.com/content/dam/wbx/us/images/dg-integ/teams_icon.png"
2425

2526

2627
# Create a WebexTeamsAPI connection object; uses your WEBEX_TEAMS_ACCESS_TOKEN

webexteamssdk/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,17 +268,17 @@ class WebexTeamsDateTime(datetime):
268268

269269
@classmethod
270270
def strptime(cls, date_string, format=WEBEX_TEAMS_DATETIME_FORMAT):
271-
"""strptime with the Spark DateTime format as the default."""
271+
"""strptime with the Webex Teams DateTime format as the default."""
272272
return super(WebexTeamsDateTime, cls).strptime(
273273
date_string, format
274274
).replace(tzinfo=ZuluTimeZone())
275275

276276
def strftime(self, fmt=WEBEX_TEAMS_DATETIME_FORMAT):
277-
"""strftime with the Spark DateTime format as the default."""
277+
"""strftime with the Webex Teams DateTime format as the default."""
278278
return super(WebexTeamsDateTime, self).strftime(fmt)
279279

280280
def __str__(self):
281-
"""Human readable string representation of this SparkDateTime."""
281+
"""Human readable string representation of this WebexTeamsDateTime."""
282282
dt = self.astimezone(ZuluTimeZone())
283283
return dt.strftime("%Y-%m-%dT%H:%M:%S.{:0=3}%Z").format(
284284
self.microsecond // 1000

0 commit comments

Comments
 (0)