Installation and Quickstart
Rooms
Messages
Cards
python_webex_bot
A python3 library meant to help you create a cisco webex teams bot and take advantage of some of the features available to these bots. Most of the python libraries setup for webex have been lacking in terms of connecting you to a webhook and this aims at solving that
Installation and setup
The following are items this documentation assumes you already have installed
- virtualenv
- python3
- ngrok
Step 1: setup the virtual environment
to initialize the virtual environment, run the following command in your Command Line or Command Prompt
virtualenv venv
then we activate it:
Windows
venv\Scripts\activate
Linux
source venv/bin/activate
and there, you have your virtual environment setup and ready for action
Step 2: install python_webex_bot
while still in your activated virtual environment, run the following command to install python_webex_bot via pip:
pip install python_webex_bot
then download ngrok which will be used in the concurrent steps
Quickstart
Lets get a simple bot up, running and responsive on our local machine.
Step 1: Create the bot on Cisco Webex
If you haven't already, create your Webex account. Then head on to create your bot
You should be provided with an access token for the bot.
Take this access token and place it in your environment variable as auth_token.
this can be done via your Command prompt or Command Line as:
set auth_token=my_auth_token
replace my_auth_token with your bots access token
This is a crutial part of running your bot as the python_webex_bot library uses this to identify your bot
If you still have some questions on environment variables, why we need them and how to use them, this may be a good start
Step 2: setup ngrok
in a different terminal from the one used in steps 1 and 2, navigate to the folder where you have the ngrok placed.
Then run the following command:
ngrok http 5000
This should produce an output similar to the one shown below:
Session Status online
Session Expires 7 hours, 59 minutes
Update update available (version 2.3.25, Ctrl-U to update)
Version 2.3.18
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding http://87a942a1.ngrok.io -> http://localhost:5000
Forwarding https://87a942a1.ngrok.io -> http://localhost:5000
Connections ttl opn rt1 rt5 p50 p90
0 0 0.00 0.00 0.00 0.00
Now you are ready for the quest
Step 3: create the python file and run it
Create a python file where you intend to run the bot. In my case, I will name my file run.py
copy and paste the following code:
from python_webex.v1.Bot import Bot
from python_webex import webhook
bot = Bot() # the program will automatically know the bot being referred to y the auth_token
# create a webhook to expose it to the internet
# rememer that url we got from step 2, this is where we use it. In my case it was http://87a942a1.ngrok.io.
# We will be creating a webhook that will be listening when messages are sent
bot.create_webhook(
name="quickstart_webhook", target_url="http://87a942a1.ngrok.io", resource="messages", event="created"
)
# we create a function that responds when someone says hi
# the room_id will automatically be filled with the webhook. Do not forget it
@bot.on_hears("hi")
def greet_back(room_id=None):
return bot.send_message(room_id=room_id, text="Hi, how are you doing?")
# We create a default response in case anyone types anything else that we have not set a response for
# this is done using * [ don't ask me what happend when someone sends '*' as the message, that's on my TODO]
@bot.on_hears("*")
def default_response(room_id=None):
return bot.send_message(room_id=room_id, text="Sorry, could not understand that")
# make the webhook know the bot to be listening for, and we are done
webhook.bot = bot
if __name__ == "__main__":
webhook.app.run(debug=True) # don't keep debug=True in production
Now, when we text our bot "hi", it will respond with "Hi, how are you doing?"
And when we text anything else, like "When can we meet up?" it will respond with "Sorry, I could not understand that"
FIND MORE DOCUMENTATION here
Metadata
Release files for python-webex-bot 0.901
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| python_webex_bot-0.901.tar.gz | 14.4 kB | Without provenance | Details for python_webex_bot-0.901.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_webex_bot-0.901-py3-none-any.whl | Python 3 | none | any | Details for python_webex_bot-0.901-py3-none-any.whl |
Total release size: 29.0 kB
Release files / python_webex_bot-0.901.tar.gz
| Download URL | python_webex_bot-0.901.tar.gz |
|---|---|
| Size | 14.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d1e1e852546b51497746599a73b3390c945ff26caa0b6922bddf807833751c4d
|
|
BLAKE2b-256 checksum How to use checksums |
f57a118a48968cb77a4669aaa23f77ad78ce215daeaa93e99b9025c7dc73293d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.6
|
Release files / python_webex_bot-0.901-py3-none-any.whl
| Download URL | python_webex_bot-0.901-py3-none-any.whl |
|---|---|
| Size | 14.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a513277ab70b5b1326652cde449c461ec1766569e4b1248558661acdf11b2f31
|
|
BLAKE2b-256 checksum How to use checksums |
b55a167b2d3215f9b388ff80230f41daf911ae31333ad19fe7eacc073a5c42b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.6
|
Security for python-webex-bot 0.901
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.