Webex BOT that preserves messages written by moderators of an only announcement space. The messages are preserved in a DB until deleted by the moderators. The messages will be preserved if deleted by non-moderators.
- Max Acquatella
This is SAMPLE CODE, it does not follow code security best practices (token and password security enforcement), its purpose is to demonstrate the use of Cisco APIs, not recommended to use in production environments.
-
Webex Organization, familiarity with Webex for Developers, Webex SDK, Webhooks and obtaining information using Webex REST APIs. https://developer.webex.com/
-
Familiarity with NGROK tunnels: https://ngrok.com/
NOTE: This code was tested using macOS Python3 virtual environments. For Windows Python3 Virtual Environments please see: https://www.youtube.com/watch?v=APOPm01BVrk
Download Code:
git clone https://wwwin-github.cisco.com/gve/gve_devnet_announcementspace_message_preservation_bot.git
Virtual Environment
python3 -m venv env
source env/bin/activate
Install Requirements.txt
pip3 install -r requirements.txt
NGROK: PLease follow the instruction to download and install NGROK from the following website:
NOTE: By the time of this writing, Webex and NGROK had communications issues, so we tested the NGROK tunnel using the --region UE
ngrok http 8080 --region=eu
The code uses the local port 8080, this can be changed if required.
Save the public URL in credentials.py
Use the following Webex API to extract the room ID (create a new Room if it does not exist):
https://developer.webex.com/docs/api/v1/rooms/list-rooms
Assign moderators to the Room/Space
Obtain Webex Admin temporary token using this link:
https://developer.webex.com/docs/getting-started
Save token in credentials.py NOTE: The previous token will last only for 12 hours. For a permanent token please create an integration. See:
https://developer.webex.com/docs/integrations
In credentials.py, fill out the list named 'admin_emails' with the moderators of the room. These administrators will be able to write messages in the room and delete said messages both from the room and from the database. Messages deleted by any other user NOT in this list should be preserved and reposted by the code. In order to promote a user from the announcement space, just right-click the user and promote to moderator. This user will be able to post/delete messages in the space, though if this user is not in the list of admins, the messages deleted by the "non-admin" user will be reposted.
There is an auxiliary script to register the required webhook, please run this script first. The Webhook ID will be saved in "webhook_id.json". The main script will pull the Webhook ID from this json document.
python3 set_up_webex_webhooks.py
Make sure that all the required credentials are in place:
Via command line, start the FLASK application:
python3 app.py
The code will add a database folder, which will contain the messages created by the room admins/moderators.
The code will output multiple messages:
Once the Space moderators post messages, the code will create a database called "messages_db.db" and store messages posted by moderators. Moderators that are not admininistrator will be able to post messages, but if said moderators delete messages, these deleted messages will be reposted by the code (on behalf of the user that created the Webex API Token).
Provided under Cisco Sample Code License, for details see LICENSE
Our code of conduct is available here
See our contributing guidelines here
Please note: This script is meant for demo purposes only. All tools/ scripts in this repo are released for use "AS IS" without any warranties of any kind, including, but not limited to their installation, use, or performance. Any use of these scripts and tools is at your own risk. There is no guarantee that they have been through thorough testing in a comparable environment and we are not responsible for any damage or data loss incurred with their use. You are responsible for reviewing and testing any scripts you run thoroughly before use in any non-testing environment.