2017-10-04 21:11:27 +02:00
|
|
|
# Interactive bots
|
2017-10-02 13:19:41 +02:00
|
|
|
|
2017-10-04 21:11:27 +02:00
|
|
|
Zulip's API has a powerful framework for interactive bots that react
|
2018-01-26 13:37:54 +01:00
|
|
|
to messages in Zulip. This page documents how to run a bot
|
2017-10-04 21:11:27 +02:00
|
|
|
implemented using that framework, both on your laptop for quick
|
|
|
|
testing as well in a production server environment.
|
2017-10-02 13:19:41 +02:00
|
|
|
|
|
|
|
On this page you'll find:
|
|
|
|
|
2017-10-04 18:01:31 +02:00
|
|
|
* A step-by-step [tutorial](#running-a-bot) on how to run a bot.
|
2017-10-02 13:19:41 +02:00
|
|
|
* Common [problems](#common-problems) when developing/running bots and their solutions.
|
|
|
|
|
2017-11-17 14:12:37 +01:00
|
|
|
## Installing the Zulip bots package
|
2017-10-02 13:19:41 +02:00
|
|
|
|
2017-10-04 18:01:31 +02:00
|
|
|
## Running a bot
|
2017-10-02 13:19:41 +02:00
|
|
|
|
2018-05-14 02:58:03 +02:00
|
|
|
This guide will show you how to run an **existing** Zulip bot
|
2017-10-04 18:12:34 +02:00
|
|
|
found in [`zulip_bots/bots`](
|
2018-05-14 02:58:03 +02:00
|
|
|
https://github.com/zulip/python-zulip-api/tree/master/zulip_bots/zulip_bots/bots).
|
2017-10-02 13:19:41 +02:00
|
|
|
|
|
|
|
You need:
|
|
|
|
|
|
|
|
* An account in an organization on a Zulip server
|
|
|
|
(e.g. [chat.zulip.org](https://chat.zulip.org) or
|
|
|
|
yourSubdomain.zulipchat.com, or your own development server).
|
|
|
|
Within that Zulip organization, users will be able to interact with
|
|
|
|
your bot.
|
|
|
|
* A computer where you're running the bot from.
|
|
|
|
|
2017-12-14 22:00:15 +01:00
|
|
|
**Note: Please be considerate when testing experimental bots on public servers such as chat.zulip.org.**
|
2017-10-02 13:19:41 +02:00
|
|
|
|
2017-10-04 21:11:27 +02:00
|
|
|
1. Run `pip install zulip_bots` to install the package.
|
|
|
|
|
2017-11-15 11:49:15 +01:00
|
|
|
*Hint: Do you want to install the latest development version? Check
|
|
|
|
out [this](
|
2017-11-18 00:55:42 +01:00
|
|
|
writing-bots#installing-a-development-version-of-the-zulip-bots-package)
|
2017-11-15 11:49:15 +01:00
|
|
|
guide.*
|
2017-10-02 13:19:41 +02:00
|
|
|
|
2018-05-14 02:43:32 +02:00
|
|
|
1. Register a new bot user on the Zulip server's web interface.
|
2017-10-02 13:19:41 +02:00
|
|
|
|
|
|
|
* Log in to the Zulip server.
|
|
|
|
* Navigate to *Settings (<i class="fa fa-cog"></i>)* -> *Your bots* -> *Add a new bot*.
|
|
|
|
Select *Generic bot* for bot type, fill out the form and click on *Create bot*.
|
|
|
|
* A new bot user should appear in the *Active bots* panel.
|
|
|
|
|
2018-05-14 02:43:32 +02:00
|
|
|
1. Download the bot's `zuliprc` configuration file to your computer.
|
2017-10-02 13:19:41 +02:00
|
|
|
|
2018-05-14 03:02:22 +02:00
|
|
|
* Go to *Settings* -> *Your bots*.
|
2017-10-02 13:19:41 +02:00
|
|
|
* In the *Active bots* panel, click on the little green download icon
|
2017-11-21 00:49:55 +01:00
|
|
|
to download its configuration file *zuliprc* (the structure of this file is
|
2017-11-15 11:49:15 +01:00
|
|
|
explained [here](writing-bots#configuration-file)).
|
2017-11-21 00:49:55 +01:00
|
|
|
* The file will be downloaded to some place like `~/Downloads/zuliprc` (depends
|
|
|
|
on your browser and OS).
|
|
|
|
* Copy the file to a destination of your choice, e.g. to `~/zuliprc-my-bot`.
|
2017-10-02 13:19:41 +02:00
|
|
|
|
2018-05-14 03:37:52 +02:00
|
|
|
1. Start the bot process.
|
2017-10-02 13:19:41 +02:00
|
|
|
|
|
|
|
* Run
|
|
|
|
```
|
2017-11-21 00:49:55 +01:00
|
|
|
zulip-run-bot <bot-name> --config-file ~/zuliprc-my-bot
|
2017-10-02 13:19:41 +02:00
|
|
|
```
|
2017-11-21 00:49:55 +01:00
|
|
|
(using the path to the `zuliprc` file from step 3).
|
2018-05-14 03:37:52 +02:00
|
|
|
* Check the output of the command. It should include the following line:
|
2017-10-02 13:19:41 +02:00
|
|
|
|
2017-12-14 22:00:15 +01:00
|
|
|
INFO:root:starting message handling...
|
2017-10-02 13:19:41 +02:00
|
|
|
|
2018-05-14 03:37:52 +02:00
|
|
|
Congrats! Your bot is running.
|
|
|
|
|
|
|
|
1. To talk with the bot, mention its name `@**bot-name**`.
|
2017-10-02 13:19:41 +02:00
|
|
|
|
2017-10-04 21:11:27 +02:00
|
|
|
You can now play around with the bot and get it configured the way you
|
|
|
|
like. Eventually, you'll probably want to run it in a production
|
|
|
|
environment where it'll stay up, by deploying it on a server using the
|
|
|
|
Zulip Botserver.
|
2017-10-02 13:19:41 +02:00
|
|
|
|
|
|
|
## Common problems
|
|
|
|
|
|
|
|
* My bot won't start
|
|
|
|
* Ensure that your API config file is correct (download the config file from the server).
|
2017-12-12 15:12:24 +01:00
|
|
|
* Ensure that your bot script is located in zulip_bots/bots/<my-bot>/
|
2017-10-02 13:19:41 +02:00
|
|
|
* Are you using your own Zulip development server? Ensure that you run your bot outside
|
|
|
|
the Vagrant environment.
|
|
|
|
* Some bots require Python 3. Try switching to a Python 3 environment before running
|
|
|
|
your bot.
|