print(bot_app_name, spark_token, bot_url, bot_email) # 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', 'sample that allows spark message to be returned', ret_message) bot.add_command( '/showping', 'Returns ping results with packet count set to 1. Usage: /showping DESTINATION', ping_message) bot.add_command( '/pingip', 'checks if IP address is up/down (valid/invalid). Usage: /pingip DESTINATION', pingip_message) bot.add_command('/routefilter', 'invokes route-filter shell script.', routefilter_message) bot.add_command( '/link', 'Returns the URL that matches the link name. Usage: /link LINK_NAME', get_link) # Run Bot bot.run(host='127.0.0.1', port=5000)
# Get Bot Identity 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 chuck_joke(message): # Use urllib to get a random joke import urllib2 import json response = urllib2.urlopen('http://api.icndb.com/jokes/random') joke = json.loads(response.read())["value"]["joke"] # Return the text of the joke return joke # Create New Bot Object bot = SparkBot(bot_app_name, spark_bot_token=spark_token, spark_bot_url=bot_url, spark_bot_email=bot_email) # Teach bot to tell Chuck Norris Jokes bot.add_command("/chuck", "Get a random Chuck Norris Joke", chuck_joke) # Start Your Bot bot.run(host='0.0.0.0', port=5000)
bot.add_command('help', 'Get help.', bot.send_help) bot.remove_command('/echo') bot.remove_command('/help') # Add bot commands. # If Meraki environment variables have been enabled, add Meraki-specifc commands. if cico_common.meraki_support(): bot.add_command('meraki-health', 'Get health of Meraki environment.', cico_meraki.get_meraki_health_html) bot.add_command('meraki-check', 'Check Meraki user status.', cico_meraki.get_meraki_clients_html) # If Spark Call environment variables have been enabled, add Spark Call-specifc commands. if cico_common.spark_call_support(): bot.add_command('spark-health', 'Get health of Spark environment.', cico_spark_call.get_spark_call_health_html) bot.add_command('spark-check', 'Check Spark user status.', cico_spark_call.get_spark_call_clients_html) # If Umbrella (S3) environment variables have been enabled, add Umbrella-specifc commands. if cico_common.umbrella_support(): bot.add_command('umbrella-health', 'Get health of Umbrella envrionment.', cico_umbrella.get_umbrella_health_html) bot.add_command('umbrella-check', 'Check Umbrella user status.', cico_umbrella.get_umbrella_clients_html) # Add generic commands. bot.add_command('health', 'Get health of entire environment.', cico_combined.get_health) bot.add_command('check', 'Get user status.', cico_combined.get_clients) # Run Bot bot.run(host='0.0.0.0', port=app_port)
# query (string) The search term to query by. # offset (number) For use to add pagenation for search results e.g. 10 to start with the 11th result. Default is 0. # limit (number) The number of results to return. Default is 10. conn.request("GET", "/grocery/products/?query={}&offset={}&limit={}&".format(query,offset,limit), "{body}", tesco_headers) response = conn.getresponse() search_response_data = response.read() print(search_response_data) conn.close() except Exception as e: print("[Errno {0}] {1}".format(e.errno, e.strerror)) # Turn raw JSON results into a string res_str res_str = json.loads(search_response_data) #return results nicely formatted with indent=2 return "Grocery search results from devportal.tescolabs.com in raw JSON:\n ``` {}".format(json.dumps(res_str, indent=2)) # Create a new bot tescobot = SparkBot(bot_app_name, spark_bot_token=spark_token, spark_bot_url=bot_url, spark_bot_email=bot_email, debug=True) # Add new command tescobot.add_command('/search', 'Look up a product on tesco.com', grocery_search) tescobot.add_command('/jsearch', 'Return raw JSON output of grocery search [/jsearch query offset limit]', json_grocery_search) # Run Bot tescobot.run(host='0.0.0.0', port=5000)
#bot_url = os.getenv("SPARK_BOT_URL") #bot_app_name = os.getenv("SPARK_BOT_APP_NAME") bot_email = "*****@*****.**" spark_token = "MGUzMjJlYjAtM2Q0Zi00N2EwLWE5ZmItZTdmY2VkM2MxZWJhYzEzNzIwOWItOWQ1" bot_url = "http://cd5ded8a.ngrok.io" bot_app_name = "Ziggleflig" 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) # 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) # Run Bot bot.run(host='127.0.0.1', port=13245)