Chatrouter is an enhanced router for chatbots and easily integrates with any bot library.
## key features
1. turned complexity into simplicity.
from:
```python
if user_session == "A":
...
elif user_session == "B":
...
elif user_session == "C":
...
else:
...
```
to:
```python
chatbot = chatrouter.group(user_session)
r = chatrouter.run(chatbot, msg)
```
2. Readable route.
```python
@chatbot.add_command("call me {my_name}")
# or
chatbot.add_command("call me {my_name} and {my_friend}")
# etc
```
3. case sensitive and insensitive.
default case is `insensitive` but you can add `strict=True` to a route/command to make it case sensitive.
4. public and private command.
command start with "/" and have description is public command, for example:
```python
@chatbot.add_command("/test", description="test command", strict=True)
```
5. invoke callback anywhere.
```python
func = chatrouter.util.get_func("group_name", "command_name")
```
6. auto generated `/start` and `/help` command.
7. object storage `chatrouter.data_user`.
## installation
```
pip install chatrouter
```
## quick example
```python
# -*-coding:utf8;-*-
import chatrouter
chatbot = chatrouter.group("test", "this is test bot!")
@chatbot.add_command("call me {name}")
def say_handler(name):
return f"hello {name}, nice to meet you!"
@chatbot.add_command("repeat me {one} and {two}")
def repeat_handler(one, two):
return f"ok {one}.. {two}"
@chatbot.add_default_command()
def default_handler(command):
return f"command {command} not found!"
if __name__ == '__main__':
print(chatrouter.run(chatbot, "/start"))
while True:
try:
i = input("you: ")
r = chatrouter.run(chatbot, i)
print(f"bot: {r}")
except BaseException as e:
print("bot: byebye!")
exit(0)
```
for more complex example, please open [demo/telegram_bot](https://github.com/cirebon-dev/chatrouter/tree/main/demo/telegram_bot).
Raw data
{
"_id": null,
"home_page": "https://github.com/cirebon-dev/chatrouter",
"name": "chatrouter",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "guangrei",
"author_email": "myawn@pm.me",
"download_url": "https://files.pythonhosted.org/packages/21/46/495ee766ed799016c74214c1fdb459579eeabc445cc6d47e091d7b83dc63/chatrouter-1.0.4.tar.gz",
"platform": "any",
"description": "Chatrouter is an enhanced router for chatbots and easily integrates with any bot library.\n\n## key features\n\n1. turned complexity into simplicity.\n\nfrom:\n```python\nif user_session == \"A\":\n ...\nelif user_session == \"B\":\n ...\nelif user_session == \"C\":\n ...\nelse:\n ...\n```\nto:\n```python\nchatbot = chatrouter.group(user_session)\nr = chatrouter.run(chatbot, msg)\n```\n2. Readable route.\n\n```python\n@chatbot.add_command(\"call me {my_name}\")\n# or \nchatbot.add_command(\"call me {my_name} and {my_friend}\")\n# etc\n```\n\n3. case sensitive and insensitive.\n\ndefault case is `insensitive` but you can add `strict=True` to a route/command to make it case sensitive.\n\n4. public and private command.\n\ncommand start with \"/\" and have description is public command, for example:\n```python\n@chatbot.add_command(\"/test\", description=\"test command\", strict=True)\n```\n5. invoke callback anywhere.\n\n```python\nfunc = chatrouter.util.get_func(\"group_name\", \"command_name\")\n```\n\n6. auto generated `/start` and `/help` command.\n\n7. object storage `chatrouter.data_user`.\n\n## installation\n\n```\npip install chatrouter\n```\n\n## quick example\n\n```python\n# -*-coding:utf8;-*-\nimport chatrouter\n\n\nchatbot = chatrouter.group(\"test\", \"this is test bot!\")\n\n\n@chatbot.add_command(\"call me {name}\")\ndef say_handler(name):\n return f\"hello {name}, nice to meet you!\"\n\n\n@chatbot.add_command(\"repeat me {one} and {two}\")\ndef repeat_handler(one, two):\n return f\"ok {one}.. {two}\"\n\n\n@chatbot.add_default_command()\ndef default_handler(command):\n return f\"command {command} not found!\"\n\n\nif __name__ == '__main__':\n print(chatrouter.run(chatbot, \"/start\"))\n while True:\n try:\n i = input(\"you: \")\n r = chatrouter.run(chatbot, i)\n print(f\"bot: {r}\")\n except BaseException as e:\n print(\"bot: byebye!\")\n exit(0)\n\n```\n\nfor more complex example, please open [demo/telegram_bot](https://github.com/cirebon-dev/chatrouter/tree/main/demo/telegram_bot).\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Router for chatbot",
"version": "1.0.4",
"project_urls": {
"Homepage": "https://github.com/cirebon-dev/chatrouter"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2146495ee766ed799016c74214c1fdb459579eeabc445cc6d47e091d7b83dc63",
"md5": "2364de97a2770099184f1077d7be3e52",
"sha256": "4b366d90bc69c5beee87e0a5a6de0e7e26403fb8b0c1cd28daafcc335386a91c"
},
"downloads": -1,
"filename": "chatrouter-1.0.4.tar.gz",
"has_sig": false,
"md5_digest": "2364de97a2770099184f1077d7be3e52",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3898,
"upload_time": "2024-02-18T14:49:44",
"upload_time_iso_8601": "2024-02-18T14:49:44.597445Z",
"url": "https://files.pythonhosted.org/packages/21/46/495ee766ed799016c74214c1fdb459579eeabc445cc6d47e091d7b83dc63/chatrouter-1.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-18 14:49:44",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "cirebon-dev",
"github_project": "chatrouter",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "chatrouter"
}