A Flask based Webex Teams chat bot.
Project description
webexteamsbot
This package makes creating Webex Teams bots in Python super simple.
This package is based on the previous ciscosparkbot project. This version will both move to new Webex Teams branding as well as add new functionality. If you've used
ciscosparkbot
you will find this package very similar and familiar.
Prerequisites
If you don't already have a Webex Teams account, go ahead and register for one. They are free.
-
You'll need to start by adding your bot to the Webex Teams website.
-
Click Create a New App
-
Click Create a Bot.
-
Fill out all the details about your bot. You'll need to set a name, username, icon (either upload one or choose a sample), and provide a description.
-
Click Add Bot.
-
On the Congratulations screen, make sure to copy the Bot's Access Token, you will need this in a second.
Installation
Python 3.6+ is recommended. Python 2.7 should also work.
-
Create a virtualenv and install the module
python3.6 -m venv venv source venv/bin/activate pip install webexteamsbot
Usage
-
The easiest way to use this module is to set a few environment variables
Note: See ngrok for details on setting up an easy HTTP tunnel for development.
export TEAMS_BOT_URL=https://mypublicsite.io export TEAMS_BOT_TOKEN=<your bots token> export TEAMS_BOT_EMAIL=<your bots email> export TEAMS_BOT_APP_NAME=<your bots name>
-
A sample script is also provided for your convenience
# -*- coding: utf-8 -*- """ Sample code for using webexteamsbot """ import os from webexteamsbot import TeamsBot from webexteamsbot.models import Response # Retrieve required details from environment variables bot_email = os.getenv("TEAMS_BOT_EMAIL") teams_token = os.getenv("TEAMS_BOT_TOKEN") bot_url = os.getenv("TEAMS_BOT_URL") bot_app_name = os.getenv("TEAMS_BOT_APP_NAME") def do_something(incoming_msg): """ Sample function to do some action. :param incoming_msg: The incoming message object from Teams :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 = TeamsBot( bot_app_name, teams_bot_token=teams_token, teams_bot_url=bot_url, teams_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 Webex Teams message to be returned", ret_message, ) # Run Bot bot.run(host="0.0.0.0", port=5000)
ngrok
ngrok will make easy for you to develop your code with a live bot.
You can find installation instructions here: https://ngrok.com/download
-
After you've installed
ngrok
, in another window start the servicengrok http 5000
-
You should see a screen that looks like this:
ngrok by @inconshreveable (Ctrl+C to quit) Session Status online Version 2.2.4 Region United States (us) Web Interface http://127.0.0.1:4040 Forwarding http://this.is.the.url.you.need -> localhost:5000 Forwarding https://this.is.the.url.you.need -> localhost:5000 Connections ttl opn rt1 rt5 p50 p90 2 0 0.00 0.00 0.77 1.16 HTTP Requests ------------- POST / 200 OK
-
Make sure and update your environment with this url:
export TEAMS_BOT_URL=https://this.is.the.url.you.need
-
Now launch your bot!!
python sample.py
Local Development
If you have an idea for a feature you would like to see, we gladly accept pull requests. To get started developing, simply run the following..
git clone https://github.com/hpreston/webexteamsbot
cd webexteamsbot
pip install -r requirements_dev.txt
python setup.py develop
Linting
We use flake 8 to lint our code. Please keep the repository clean by running:
flake8
Credits
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
History
0.1.0 (2018-11-10)
- First release on PyPI.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for webexteamsbot-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 798ad311a080ce0f52fbebd838a6b0463b6e2473a2fe3b97101dcdf4aeab3b05 |
|
MD5 | 01e0875efee2fecd0f2f95e996522ea5 |
|
BLAKE2b-256 | 16854b88033b727e3166014571ef1d3409fe4afa90c56ec7d3b3a875a408784e |