|
37 | 37 |
|
38 | 38 |
|
39 | 39 | # Module constants
|
40 |
| -CHUCK_NORRIS_JOKES_URL = 'http://api.icndb.com/jokes/random' |
| 40 | +CAT_FACT_URL = 'http://catfacts-api.appspot.com/api/facts?number=1' |
41 | 41 |
|
42 | 42 |
|
43 | 43 | # Initialize the environment
|
44 | 44 | spark_api = CiscoSparkAPI() # Create the Cisco Spark API connection object
|
45 | 45 |
|
46 | 46 |
|
47 | 47 | # Helper functions
|
48 |
| -def get_chuck_norris_joke(): |
49 |
| - """Get a Chuck Norris Joke from api.icndb.com and return it as a string. |
| 48 | +def get_catfact(): |
| 49 | + """Get a cat fact from catfacts-api.appspot.com and return it as a string. |
50 | 50 | Functions for Soundhound, Google, IBM Watson, or other APIs can be added
|
51 | 51 | to create the desired functionality into this bot.
|
52 | 52 | """
|
53 |
| - response = requests.get(CHUCK_NORRIS_JOKES_URL, verify=False) |
| 53 | + response = requests.get(CAT_FACT_URL, verify=False) |
54 | 54 | response_dict = json.loads(response.text)
|
55 |
| - return response_dict['value']['joke'] |
| 55 | + return response_dict['facts'][0] |
56 | 56 |
|
57 | 57 |
|
58 | 58 | sparkwebhook = Service(name='sparkwebhook', path='/sparkwebhook', description="Spark Webhook")
|
59 | 59 |
|
60 | 60 |
|
61 | 61 | @sparkwebhook.get()
|
62 | 62 | def get_sparkwebhook(request):
|
63 |
| - log.info(get_chuck_norris_joke()) |
64 |
| - return {"joke": get_chuck_norris_joke()} |
| 63 | + log.info(get_catfact()) |
| 64 | + return {"fact": get_catfact()} |
65 | 65 |
|
66 | 66 | @sparkwebhook.post()
|
67 |
| -# Your Spark webhook should point to http://<serverip>:5000/sparkwebhook |
| 67 | +# Your Spark webhook should point to http://<serverip>:6543/sparkwebhook |
68 | 68 | def post_sparkwebhook(request):
|
69 | 69 | """Respond to inbound webhook JSON HTTP POST from Cisco Spark."""
|
70 | 70 |
|
@@ -93,10 +93,10 @@ def post_sparkwebhook(request):
|
93 | 93 |
|
94 | 94 | else:
|
95 | 95 | # Message was sent by someone else; parse message and respond.
|
96 |
| - if "/CHUCKNORRIS" in message.text: |
97 |
| - log.info("FOUND '/CHUCKNORRIS'") |
98 |
| - chuck_norris_joke = get_chuck_norris_joke() # Get a Chuck Norris Joke |
99 |
| - log.info("SENDING CHUCK NORRIS JOKE '{}'".format(chuck_norris_joke)) |
100 |
| - spark_api.messages.create(room.id, text=chuck_norris_joke) # Post the fact to the room where the request was received |
| 96 | + if "/CAT" in message.text: |
| 97 | + log.info("FOUND '/CAT'") |
| 98 | + catfact = get_catfact() # Get a cat fact |
| 99 | + log.info("SENDING CAT FACT'{}'".format(catfact)) |
| 100 | + spark_api.messages.create(room.id, text=catfact) # Post the fact to the room where the request was received |
101 | 101 | return {'Message': 'OK'}
|
102 | 102 |
|
0 commit comments