https://github.com/ntk148v/rocketbot
Python framework to build RocketChat bot
https://github.com/ntk148v/rocketbot
bot bot-framework python-3 rocketchat rocketchat-bot
Last synced: about 1 year ago
JSON representation
Python framework to build RocketChat bot
- Host: GitHub
- URL: https://github.com/ntk148v/rocketbot
- Owner: ntk148v
- License: apache-2.0
- Created: 2023-01-09T10:20:22.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-01-12T08:12:58.000Z (over 3 years ago)
- Last Synced: 2025-04-13T07:16:20.432Z (about 1 year ago)
- Topics: bot, bot-framework, python-3, rocketchat, rocketchat-bot
- Language: Python
- Homepage:
- Size: 32.2 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Table of contents
- [1. Installation](#1-installation)
- [2. Usage](#2-usage)
- [2.1. Create new bot](#21-create-new-bot)
- [2.2. Create a new plugin (command)](#22-create-a-new-plugin-command)
- [2.3. Custom logger configuration](#23-custom-logger-configuration)
- [2.4. Run it](#24-run-it)
- [3. Credits](#3-credits)
## 1. Installation
```shell
pip install git+https://github.com/ntk148v/rocketbot.git
```
## 2. Usage
Check out the [sample](./sample.py).
### 2.1. Create new bot
```python
import os
from rocketbot import RocketBot
username = os.environ.get('ROCKET_USERNAME')
password = os.environ.get('ROCKET_PASSWORD')
server_url = os.environ.get('ROCKET_SERVER_URL')
rocket = RocketBot(user=username, password=password,
server_url=server_url, ssl_verify=False,
session=requests.sessions.Session(),
threading_updates=True)
```
### 2.2. Create a new plugin (command)
You can add a new plugin to initialized bot by using decorator `add_command`. `add_command` requires 2 arguments:
- The regex that bot will respond if matching.
- The bot's usage.
```python
@rocket.add_command(r'/start', usage='Start working with bot')
def start(message, *args):
rocket.send_message(
message['rid'], f"hi @{message['u']['username']}, let's start")
```
### 2.3. Custom logger configuration
By default, RocketBot writes log to stderr with default level is "INFO". You can customize it by passing a configuration dict. You can refer to [loguru's offical document](https://loguru.readthedocs.io/en/stable/api/logger.html#loguru._logger.Logger.configure).
```python
rocket = RocketBot(user=username, password=password,
server_url=server_url, ssl_verify=False,
session=requests.sessions.Session(),
logger_config={
"handlers": [
{"sink": sys.stdout, "format": "{time} - {message}"},
{"sink": "/tmp/file.log", "serialize": True},
],
},
threading_updates=True)
```
### 2.4. Run it
```python
rocket.run(sleep=10)
```
## 3. Credits
This library is highly inspired by:
- [seyed-dev/rocketchatbot](https://github.com/seyed-dev/rocketchatbot)
- [jadolg/RocketChatBot](https://github.com/jadolg/RocketChatBot)