New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add developer documentation for bots #2766
Conversation
Automated message from Dropbox CLA bot @derAnfaenger, it looks like you've already signed the Dropbox CLA. Thanks! |
@@ -0,0 +1,188 @@ | |||
# Developing bots | |||
**This feature is still experimental** | |||
Bots are a new system in Zulip, allowing developers to react to messages. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Say "The contrib_bots system is a new part of Zulip that allows bot developers to write a large class of bots by simply reacting to message."
Contributions to this guide are very welcome, so if you run into any | ||
issues following these instructions or come up with any tips or tools | ||
that help writing integration, please email | ||
zulip-devel@googlegroups.com, open an issue, or submit a pull request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tell them instead to go to chat.zulip.org.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed that I didn't change the "writing integration" part, will do so as well.
* A new bot should appear in the *Your Bots* panel. | ||
4. Add the bot's configuration file on your Zulip server. | ||
* In the *Your Bots* panel, click on the green icon to download its configuration file *.zuliprc* (the structure of this file is explained [here](#configuration-file) | ||
* Copy the file to a destination of your choice on your Zulip server, e.g. to `~/.zuliprc` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.g. to ~/.zuliprc or ~/zuliprc-test.
4. Add the bot's configuration file on your Zulip server. | ||
* In the *Your Bots* panel, click on the green icon to download its configuration file *.zuliprc* (the structure of this file is explained [here](#configuration-file) | ||
* Copy the file to a destination of your choice on your Zulip server, e.g. to `~/.zuliprc` | ||
5. Subscribe the bot to the streams where you want to use it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Subscribe the bot to any streams that the bot needs to read message from or write message to.
* In the *Your Bots* panel, click on the green icon to download its configuration file *.zuliprc* (the structure of this file is explained [here](#configuration-file) | ||
* Copy the file to a destination of your choice on your Zulip server, e.g. to `~/.zuliprc` | ||
5. Subscribe the bot to the streams where you want to use it. | ||
* By default, the bot *does not intercept/send messages* on any stream. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Omit this line for now. ^^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, will do, but why?
* Copy the file to a destination of your choice on your Zulip server, e.g. to `~/.zuliprc` | ||
5. Subscribe the bot to the streams where you want to use it. | ||
* By default, the bot *does not intercept/send messages* on any stream. | ||
* To change that, navigate to *Manage Streams*. Select a stream and add your bot by its email address (the address you assigned in step 2). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To subscribe your bot to streams,...
* On your Zulip server, navigate to `~/zulip/contrib_bots/` | ||
* Run `python run.py ~/zulip/contrib_bots/<my-bot>.py --config-file ~/.zuliprc` | ||
* Congrats! Now, your bot should be ready to test on the streams you subscribed it to. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Describe what the output looks like when you start a bot. It shows usage then it shows HTTP connection stuff.
* email - the email address of the bot, e.g. `some-bot@zulip.com` | ||
* site - your development environment URL. If you are working on a development environment hosted on your computer, use `localhost:9991` | ||
##Common problems | ||
* I modified my bot's code, yet the changes don't seem to have an effect. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple other problems are you forgot to store the host or you didn't create your API config correctly.
This is an excellent start @derAnfaenger! I added a lot of comments, but the overall structure here looks great, and this will be really helpful documentation. Thanks! |
c807fe5
to
b4cd8ed
Compare
@@ -0,0 +1,192 @@ | |||
# Developing bots | |||
**This feature is still experimental** | |||
The contrib_bots system is a new part of Zulip that allows bot developers to write a large class of bots by simply reacting to message. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/message/messages/
* Run `python run.py ~/zulip/contrib_bots/<my-bot>.py --config-file ~/.zuliprc | ||
* Check the output of the command. It should start with the text the `usage` function returns, followed by logging output similar to this: | ||
|
||
>INFO:root:starting message handling... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you put this inside of triple backticks?
def usage(self): | ||
return '''Your description of the bot''' | ||
|
||
def triage_message(self, message): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a heads up that we may add another parameter here called "client." No need to address this now.
Is called by the system when a message was sent. | ||
#### Arguments | ||
* self - the instance the method is called on. | ||
* message - an object containing information about the message, e.g. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/an object/a dictionary/
Is called when `triage_message` returns true, handles user message. | ||
#### Arguments | ||
* self - the instance the method is called on. | ||
* message - an object containing information about the message, e.g. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want to de-duplicate this by saying something like "* message - a dictionary describing a Zulip message (click [here] to see more about the message fields)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with this. It kind of takes up unnecessary space.
## Common problems | ||
* I modified my bot's code, yet the changes don't seem to have an effect. | ||
* Assure that you restarted the `run.py` script. | ||
* Assure that your API config file is correct (download the config file from the server) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be a separate bullet--"My program won't start"--instead of being a sub-bullet of "I modified my bot's code...".
|
||
Contributions to this guide are very welcome, so if you run into any | ||
issues following these instructions or come up with any tips or tools | ||
that help writing bots, please visit chat.zulip.org, open an issue, or submit a pull request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that help with writing bots
4. Add the bot's configuration file on your Zulip server. | ||
* In the *Your Bots* panel, click on the green icon to download its configuration file *.zuliprc* (the structure of this file is explained [here](#configuration-file) | ||
* Copy the file to a destination of your choice on your Zulip server, e.g. to `~/.zuliprc`or ~/zuliprc-test. | ||
5. Subscribe the bot to any streams that the bot needs to read message from or write message to.55 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it is "any streams" or "any stream". Also, typo at the end "to.55"
* In the *Your Bots* panel, click on the green icon to download its configuration file *.zuliprc* (the structure of this file is explained [here](#configuration-file) | ||
* Copy the file to a destination of your choice on your Zulip server, e.g. to `~/.zuliprc`or ~/zuliprc-test. | ||
5. Subscribe the bot to any streams that the bot needs to read message from or write message to.55 | ||
* To subscribe your bot to streams, navigate to *Manage Streams*. Select a stream and add your bot by its email address (the address you assigned in step 2). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You didn't assign any address in step 2. I think you mean step 3?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @derAnfaenger!
Thanks for working on this, it looks great :)
I've had a lot of comments, but most of them were on Markdown rendering - I've been checking it while also looking at a preview of your document. Could you make sure the rendering is appropriate before you ask for your next review? You can preview the document on GitHub or usually in your editor (I'm using Atom to preview my Markdown documents).
Thanks!
With bots, you *cannot* | ||
|
||
* modify an intercepted message (you have to send a new message) | ||
* send messages in the name of other users |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say "on behalf of other users".
@@ -0,0 +1,192 @@ | |||
# Developing bots | |||
**This feature is still experimental** | |||
The contrib_bots system is a new part of Zulip that allows bot developers to write a large class of bots by simply reacting to message. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A general comment to improve readability for devs - could you try to keep the line length at 80 characters? If you make just one line break, Markdown won't pick it up as a new paragraph and it'll be easier to read on different setups.
|
||
Contributions to this guide are very welcome, so if you run into any | ||
issues following these instructions or come up with any tips or tools | ||
that help writing bots, please visit chat.zulip.org, open an issue, or submit a pull request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you write chat.zulip.org
as a link?
## How to deploy a bot | ||
This guide will show you how to deploy a bot on your running Zulip server. It presumes that you already have a fully implemented `<my-bot>.py` bot and now want to try it out. | ||
|
||
1. Copy your bot `<my-bot>.py` to `~/zulip/contrib_bots/lib/`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add line breaks after each point and it's subpoints, to improve readability.
|
||
1. Copy your bot `<my-bot>.py` to `~/zulip/contrib_bots/lib/`. | ||
* This is the place where all Zulip bots are stored. | ||
* You can also test out already existing bots in this directory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit of rephrasing You can also test out bots that already exist in this directory
.
)) | ||
``` | ||
|
||
###Configuration file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This indentation is also off, maybe because there is a missing whitespace after ###
?
email=<email> | ||
site=<dev-url> | ||
``` | ||
* key - the API key you created for the bot. This is how Zulip knows the request is from an authorized user. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, a sentence here looks a bit awkward, I'd use ;
and no full stops.
``` | ||
* key - the API key you created for the bot. This is how Zulip knows the request is from an authorized user. | ||
* email - the email address of the bot, e.g. `some-bot@zulip.com` | ||
* site - your development environment URL. If you are working on a development environment hosted on your computer, use `localhost:9991` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as line 184
* key - the API key you created for the bot. This is how Zulip knows the request is from an authorized user. | ||
* email - the email address of the bot, e.g. `some-bot@zulip.com` | ||
* site - your development environment URL. If you are working on a development environment hosted on your computer, use `localhost:9991` | ||
## Common problems |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation and rendering here are off because of missing whitespace before this line.
* Assure that you restarted the `run.py` script. | ||
* Assure that your API config file is correct (download the config file from the server) | ||
* My bot works only on some streams. | ||
* Subscribe your bot to other streams, as described [here](#how-to-deploy-a-bot). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think My bot doesn't work
is by far the most common problem.
I'd say check API keys
, check server address
and make sure your bot is subscribed to the streams you're using it in
are the most basic answers.
39fed26
to
56b9f58
Compare
@@ -0,0 +1,230 @@ | |||
# Developing bots | |||
**This feature is still experimental** | |||
The contrib_bots system is a new part of Zulip that allows |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should insert a new line break here.
|
||
### usage | ||
*usage(self)* | ||
Is called to retrieve information about the bot. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want "Is called to retrieve information about the bot." to start on a new line, you need to insert another line break. Same goes for triage_message, handle_message, etc.
Except for @lonerz and @synicalsyntax, I am asking folks to freeze review on this. This has been pretty heavily worked over, and I'm eager to merge. Once we get it merged, folks can submit follow-up PRs to clean some minor stuff like formatting issues, etc. |
@@ -0,0 +1,230 @@ | |||
# Developing bots | |||
**This feature is still experimental** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to This feature is still experimental. (period)
|
||
2. Run your Zulip server. Bots can only be deployed on running systems. | ||
|
||
3. Register a new bot at your Zulip server's web interface. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Register a new bot on your Zulip...
4. Add the bot's configuration file on your Zulip server. | ||
|
||
* In the *Your Bots* panel, click on the green icon to download its configuration file *.zuliprc* | ||
(the structure of this file is explained [here](#configuration-file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a period at the end of this sentence.
|
||
* Copy the file to a destination of your choice on your Zulip server, e.g. to `~/.zuliprc` or `~/zuliprc-test`. | ||
|
||
5. Subscribe the bot to any streams that the bot needs to read messages from or write messages to. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "subscribe the bot to the streams" sounds less ambiguous
followed by logging output similar to this: | ||
``` | ||
INFO:root:starting message handling... | ||
INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): localhost |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there some way to get both INFO lines to be indented correctly?
### handle_message | ||
*handle_message(self, message, client)* | ||
Is called when `triage_message` returns true, handles user message. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, same thing here, like usage.
#### Arguments | ||
* self - the instance the method is called on. | ||
|
||
* message - a dictionary describing a Zulip message (click [here](#triagemessage) to see more about the message fields) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Triage-message link is broken.
* client - used to interact with the server, e.g. to send a message | ||
* use client.send_message(message) to send a message | ||
|
||
* state_handler - used to save states/information of the bot**beta** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing space between bot and beta.
site=<dev-url> | ||
``` | ||
|
||
* key - the API key you created for the bot; this is how Zulip knows the request is from an authorized user. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you actually create the API key? Don't you receive an API key for the bot?
* Assure that you restarted the `run.py` script. | ||
|
||
* My bot won't start | ||
* Assure that your API config file is correct (download the config file from the server) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a period at the end of sentence.
56b9f58
to
75f988a
Compare
merged, thanks, @derAnfaenger ! |
Add a documentation for the new experimental bots support of Zulip.
Describe how to deploy and develop bots, as well as common errors and their solutions.
This is my work for the GCI task: https://codein.withgoogle.com/dashboard/task-instances/5546362475118592/
The Zulip discussion on it can be found here: https://chat.zulip.org/#narrow/stream/GCI.20tasks/topic/create.20documentation.20for.20bots.20development