Skip to content
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

Merged
merged 1 commit into from Dec 20, 2016

Conversation

roberthoenig
Copy link
Contributor

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

@smarx
Copy link

smarx commented Dec 18, 2016

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.
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

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`
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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. ^^^

Copy link
Contributor Author

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).
Copy link
Contributor

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.

Copy link
Contributor

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.
Copy link
Contributor

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.

@showell
Copy link
Contributor

showell commented Dec 18, 2016

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!

@roberthoenig roberthoenig force-pushed the documentation-bots branch 4 times, most recently from c807fe5 to b4cd8ed Compare December 18, 2016 21:09
@@ -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.
Copy link
Contributor

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...
Copy link
Contributor

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):
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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)

Copy link
Member

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)
Copy link
Contributor

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
Copy link
Member

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
Copy link
Member

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).
Copy link
Member

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?

Copy link
Member

@trueskawka trueskawka left a 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
Copy link
Member

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.
Copy link
Member

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
Copy link
Member

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/`.
Copy link
Member

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.
Copy link
Member

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
Copy link
Member

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.
Copy link
Member

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`
Copy link
Member

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
Copy link
Member

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).
Copy link
Member

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.

@roberthoenig roberthoenig force-pushed the documentation-bots branch 3 times, most recently from 39fed26 to 56b9f58 Compare December 19, 2016 22:42
@@ -0,0 +1,230 @@
# Developing bots
**This feature is still experimental**
The contrib_bots system is a new part of Zulip that allows
Copy link
Member

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.
Copy link
Member

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.

@showell
Copy link
Contributor

showell commented Dec 19, 2016

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**
Copy link
Member

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.
Copy link
Member

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)
Copy link
Member

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.
Copy link
Member

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
Copy link
Member

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.

Copy link
Member

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)
Copy link
Member

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**
Copy link
Member

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.
Copy link
Member

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)
Copy link
Member

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.

@showell showell merged commit 63e1ca0 into zulip:master Dec 20, 2016
@showell
Copy link
Contributor

showell commented Dec 20, 2016

merged, thanks, @derAnfaenger !

@roberthoenig roberthoenig deleted the documentation-bots branch December 20, 2016 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants