RSS BOT¶
The Teamwire RSS bot allows to periodically retrieve RSS feeds and push their entries as messages in Teamwire chats.
The RSS bot source code is part of the bot source code is part of the Teamwire SDK Bot Examples package:
Usage¶
After having added the bot to a chat you can send a message with the text
/rss help
to get a brief help for the available commands:
`/rss feed add <url>`: add a new rss feed to get updates from in the current chat
`/rss feed list`: return the list of feeds for the current chat
`/rss feed remove <index>`: remove a given feed
`/rss feed load <index>`: load the last 3 entries for the the given feed
`/rss time add <hour:min>`: ask the bot to send updates to this chat at the given time
`/rss time list`: list the update times for the current chat
`/rss time remove <index>`: remove a given update time
`/rss help`: list supported commands
The bot allows adding a list of feed URLs to be fetched at specific times of the day.
In order to add a feed you can use the
/rss feed add <url>
command, where <url>
is the URL of the RSS feed. Using the
/rss feed list
command, a list all the added feeds will be returned in the chat.
It is possible to set multiple feed update times in the same chat, using the
/rss time add <hour:min>
command. Similarly, in order to list the currently active update times, you can use the
/rss time list
command.
Running the bot from python sources¶
Requirements¶
In order to run the RSS bot from python sources you need to first install the Teamwire Python SDK and follow the Getting Started guide.
Running the bot¶
Note: in this section, depending on the system and environment you use, references to the python
and pip
, might need to be replaced with python3
and pip3
.
First, ensure that requirements are installed:
$ pip install -r requirements.txt
In order to start the bot you simply have to run:
$ python rssbot.py
Please ensure that the following environment variables are correctly set:
TW_API_APPID
TW_API_SECRET
TW_API_HOST
These should correspond to the bot credentials created in the Teamwire Admin dashboard.
RSS configuration storage¶
The bot configuration for each chat involving the bot (i.e. the lists of feeds and update times) are stored in a rss-conf.json
file in the current working directory of the script. In order to use a different location for the above file, it is possible to set the RSS_BOT_CONFIG
environment variable with the full path to the config file location. For example:
$ export RSS_BOT_CONFIG=/path/to/rss-conf.json
Please note that the configuration file is automatically created and managed by the bot, and it should not be modified by anyone.
Deploying the bot with Docker¶
A docker image for the RSS bot is available for Teamwire Partners on
Teamwire's Harbor Registry in the bots/rssbot
repository.
In order to deploy the above docker image in a docker environment, you should run:
docker run -d --restart always --network host --name rssbot \
-e TW_API_APPID="<YOUR APP ID>" \
-e TW_API_SECRET="<YOUR API SECRET>" \
-e TW_API_HOST="<YOUR BACKEND URL>" \
-e RSS_BOT_CONFIG="/config/rss_config.json" \
-e PYTHONIOENCODING=utf-8 \
-v /path/to/config/dir:/config \
harbor.teamwire.eu/bots/rssbot:1.6.0
The above docker run
command creates a new container named
rssbot
and passes all the required environment variables to it.
In order to make the bot configuration file independent from the container, a
volume is set, mounting the /path/to/config/dir
external directory to the
internal /config
directory. The RSS_BOT_CONFIG
environment variable
ensures that the configuration file is loaded from the volume.