-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsample.py
49 lines (38 loc) · 1.35 KB
/
sample.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# -*- coding: utf-8 -*-
"""
Sample code for using ciscosparkbot
"""
import os
from ciscosparkbot import SparkBot
from ciscosparkbot.models import Response
__author__ = "imapex"
__author_email__ = "[email protected]"
__copyright__ = "Copyright (c) 2016 Cisco Systems, Inc."
__license__ = "Apache 2.0"
# Retrieve required details from environment variables
bot_email = os.getenv("SPARK_BOT_EMAIL")
spark_token = os.getenv("SPARK_BOT_TOKEN")
bot_url = os.getenv("SPARK_BOT_URL")
bot_app_name = os.getenv("SPARK_BOT_APP_NAME")
def do_something(incoming_msg):
"""
Sample function to do some action.
:param incoming_msg: The incoming message object from Spark
:return: A text or markdown based reply
"""
return "i did what you said - {}".format(incoming_msg.text)
def ret_message(incoming_msg):
m = Response()
u = 'https://sayingimages.com/wp-content/uploads/'
u = u + 'aaaaaalll-righty-then-alrighty-meme.jpg'
m.files = u
return m
# Create a new bot
bot = SparkBot(bot_app_name, spark_bot_token=spark_token,
spark_bot_url=bot_url, spark_bot_email=bot_email, debug=True)
# Add new command
bot.add_command('/dosomething', 'help for do something', do_something)
bot.add_command('/demo', 'sampel that allows spark message to be returned',
ret_message)
# Run Bot
bot.run(host='0.0.0.0', port=5000)