Skip to content

Commit 745f2cd

Browse files
PIG208timabbott
authored andcommitted
zulip_bots: Add a boilerplate bot for external bots.
Add packaged_helloworld as an example of a PyPI package setup for an external zulip bot that can be installed via pip and lanuched without the need to include it in the zulip_bots/bots directory.
1 parent 66434d0 commit 745f2cd

File tree

5 files changed

+51
-0
lines changed

5 files changed

+51
-0
lines changed

packaged_helloworld/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This is a boilerplate package for a Zulip bot that can be installed from pip
2+
and launched using the `zulip-run-bots` command.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "1.0.0"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Simple Zulip bot that will respond to any query with a "beep boop".
2+
3+
The packaged_helloworld bot is a boilerplate bot that can be used as a
4+
template for more sophisticated/evolved Zulip bots that can be
5+
installed separately.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# See readme.md for instructions on running this code.
2+
from typing import Any, Dict
3+
4+
import packaged_helloworld
5+
6+
from zulip_bots.lib import BotHandler
7+
8+
__version__ = packaged_helloworld.__version__
9+
10+
11+
class HelloWorldHandler:
12+
def usage(self) -> str:
13+
return """
14+
This is a boilerplate bot that responds to a user query with
15+
"beep boop", which is robot for "Hello World".
16+
17+
This bot can be used as a template for other, more
18+
sophisticated, bots that can be installed separately.
19+
"""
20+
21+
def handle_message(self, message: Dict[str, Any], bot_handler: BotHandler) -> None:
22+
content = "beep boop" # type: str
23+
bot_handler.send_reply(message, content)
24+
25+
emoji_name = "wave" # type: str
26+
bot_handler.react(message, emoji_name)
27+
return
28+
29+
30+
handler_class = HelloWorldHandler

packaged_helloworld/setup.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import packaged_helloworld
2+
from setuptools import find_packages, setup
3+
4+
package_info = {
5+
"name": "packaged_helloworld",
6+
"version": packaged_helloworld.__version__,
7+
"entry_points": {
8+
"zulip_bots.registry": ["packaged_helloworld=packaged_helloworld.packaged_helloworld"],
9+
},
10+
"packages": find_packages(),
11+
}
12+
13+
setup(**package_info)

0 commit comments

Comments
 (0)