Python package for a Webex Bot based on websockets.
Project description
Introduction
By using this module, you can create a Webex bot extremely quickly in just a couple of lines of code.
Some other packages require you to set up an ngrok tunnel to receive incoming messages when behind a firewall or inside a LAN. This package instead uses a websocket to receive messages from the Webex cloud.
Features
- Uses the websockets module to receive incoming messages, thus avoiding the need to have a public IP or use incoming webhooks.
- Simply add 'commands' which are just strings which instruct the bot to perform some action and reply with some result.
- Allows for single or multi-post responses. This is useful if you want to reply with a lot of data, but it won't all fit in a single response.
- Uses the webexteamssdk package to send back replies from the bot.
Getting started
- Install this module from pypi:
pip install webex_bot
- On the Webex Developer portal, create a new bot token and expose it as an environment variable.
export WEBEX_TEAMS_ACCESS_TOKEN=<your bots token>
- Run your script:
python example.py
See example.py for details:
import os
from webex_bot.webex_bot import WebexBot
# Create a Bot Object
bot = WebexBot(teams_bot_token=os.getenv("WEBEX_TEAMS_ACCESS_TOKEN"))
def send_echo(message, teams_message):
"""
Sample command function that just echos back the sent message
:param message: message with command already stripped
:param teams_message: teams_message object. Get more info about the message received from this. e.g.
room_id = teams_message.roomId
user_email = teams_message.personEmail
raw_message = teams_message.text
:return: a string. Or a List of strings. If you return a list of strings, each will be sent in
an individual reply to the user.
"""
return message
# Add new commands for the bot to listen out for.
# bot.add_command(command, help_message, function_to_call)
bot.add_command("/echo", "Send me back the message I sent you as a demo.", send_echo)
# Call `run` for the bot to wait for incoming messages.
bot.run()
- Now, just interact 1-1 with the bot. Send it a message with the text:
/echo hello there
and you will see the reply.
History
0.1.2 (2021-03-15)
- First release on PyPI.
0.1.4 (2021-03-23)
- Better retry on websocket connection failure
- Added support for approved domains
- Other cleanup
0.1.5 (2021-03-23)
- Retry websocket connection on socket.gaierror. (#1)
0.1.6 (2021-03-25)
- Send ack on websocket message received. (#2)
0.1.7 (2021-03-26)
- Minor cleanup.
- Log bot email on startup.
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
webex_bot-0.1.7.tar.gz
(16.2 kB
view details)
Built Distribution
File details
Details for the file webex_bot-0.1.7.tar.gz
.
File metadata
- Download URL: webex_bot-0.1.7.tar.gz
- Upload date:
- Size: 16.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1827811c1f2ceb4fa151b57b60b3ef6768c63bdc5fcbf89998828ebb3d264db |
|
MD5 | bfeaa28de1a78259a80f6d51bc35fb22 |
|
BLAKE2b-256 | c69f1f8c79298b9174316a6844ed927328a9f5db1c833a13badd365212baec83 |
File details
Details for the file webex_bot-0.1.7-py2.py3-none-any.whl
.
File metadata
- Download URL: webex_bot-0.1.7-py2.py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1980f4ca1c1992e91a39d2051105f571c5d4eaee6321848b0828f0439a0ba94a |
|
MD5 | 973b9310304a32e532a874e40ff2cdd8 |
|
BLAKE2b-256 | 08c5b5f62071baa47248315b53d368cfc38a1a24124f3b4c2d0f1b090e128e29 |