-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f29bc75
Showing
21 changed files
with
6,398 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python | ||
# Poetry install: https://python-poetry.org/docs/cli/#install | ||
# https://stackoverflow.com/questions/77446605/running-python-poetry-unit-test-in-github-actions | ||
|
||
name: Python package | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
environment: release | ||
permissions: | ||
# IMPORTANT: this permission is mandatory for trusted publishing | ||
id-token: write | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: ["3.11"] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install flake8 pytest | ||
pip install poetry | ||
poetry install --with dev | ||
- name: Lint with flake8 | ||
run: | | ||
# stop the build if there are Python syntax errors or undefined names | ||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | ||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | ||
- name: Test with pytest | ||
env: | ||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | ||
run: | | ||
poetry run pytest | ||
- name: Build package | ||
run: | | ||
poetry build | ||
- name: Publish package | ||
uses: pypa/gh-action-pypi-publish@release/v1.9 | ||
|
||
# - name: Configure Git Credentials | ||
# run: | | ||
# git config user.name github-actions[bot] | ||
# git config user.email 41898282+github-actions[bot]@users.noreply.github.com | ||
|
||
# - name: Install MkDocs | ||
# run: pip install mkdocs-material | ||
|
||
# - name: Build and Deploy to GitHub Pages | ||
# run: mkdocs gh-deploy --force | ||
|
||
# - name: Deploy to GitHub Pages | ||
# uses: peaceiris/actions-gh-pages@v3 | ||
# with: | ||
# github_token: ${{ secrets.GITHUB_TOKEN }} | ||
# publish_dir: ./site |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.env | ||
/.venv | ||
/.pytest_cache | ||
/celai_chatwoot/telegram | ||
woot_test.py | ||
/.vscode | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<!-- A centered logo of celia --> | ||
<p align="center"> | ||
<img src="https://raw.githubusercontent.com/cel-ai/celai/30b489b21090e3c3f00ffea66d0ae4ac812bd839/cel/assets/celia_logo.png" width="250" /> | ||
</p> | ||
|
||
# Celai Chatwoot Connector | ||
|
||
`celai-chatwoot` is Python package that provides a connector for integrating the Cel.ai framework with Chatwoot. This allows seamless communication between your Cel.ai assistants and Chatwoot, enabling you to leverage Chatwoot's powerful customer support features. | ||
- [Cel.ai](https://github.com/cel-ai/celai) | ||
- [Chatwoot](https://www.chatwoot.com/) | ||
|
||
## Features | ||
|
||
- Easy integration with Chatwoot Bot API | ||
- Full stream mode support | ||
- Customizable bot settings | ||
|
||
## Installation | ||
|
||
You can install the `celai-chatwoot` package using pip: | ||
|
||
```bash | ||
pip install celai-chatwoot | ||
``` | ||
|
||
## Usage | ||
|
||
To use the `celai-chatwoot` connector, you need to create an instance of `WootConnector` and register it with the Cel.ai gateway. Below is an example of how to do this: | ||
|
||
```python | ||
import os | ||
from celai_chatwoot.connector import WootConnector | ||
|
||
# Create an instance of WootConnector | ||
conn = WootConnector( | ||
bot_name="Bot Name", | ||
access_key=os.environ.get("CHATWOOT_ACCESS_KEY"), | ||
account_id=os.environ.get("CHATWOOT_ACCOUNT_ID"), | ||
chatwoot_url=os.environ.get("CHATWOOT_URL"), | ||
bot_description="This is a test bot", | ||
stream_mode=StreamMode.FULL | ||
) | ||
|
||
# Register the connector with the gateway | ||
gateway.register_connector(conn) | ||
``` | ||
|
||
## Environment Variables | ||
|
||
The `WootConnector` requires the following environment variables to be set: | ||
|
||
- `CHATWOOT_ACCESS_KEY`: Your Chatwoot access key | ||
- `CHATWOOT_ACCOUNT_ID`: Your Chatwoot account ID | ||
- `CHATWOOT_URL`: The URL of your Chatwoot instance | ||
|
||
Run your Cel.ai assistant, then a new Chatwoot bot called "Bot Name" will be created in your Chatwoot instance. Assign the bot to any Inbox you want to use it with. | ||
|
||
|
||
## Roadmap | ||
|
||
Current version: 0.1.0 supports basic Chatwoot features such as sending and receiving text messages. Future versions will include the following features: | ||
|
||
- Image and file uploads | ||
- Custom attributes | ||
- Audio and video messages | ||
|
||
|
||
## Contributing | ||
|
||
We welcome contributions to the `celai-chatwoot` project. If you have any ideas, suggestions, or bug reports, please open an issue or submit a pull request. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. | ||
|
||
## Acknowledgements | ||
|
||
Special thanks to the Cel.ai and Chatwoot teams for their amazing frameworks and support. | ||
|
||
## Contact | ||
|
||
For any questions or inquiries, please contact us at [[email protected]]. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .woo_connector import WootConnector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
from woot.api import AsyncChatwoot | ||
from typing import Optional, Dict | ||
from loguru import logger as log | ||
|
||
async def create_account_bot(chatwoo_url: str, | ||
access_key: str, | ||
account_id: int, | ||
name: str, | ||
description: str): | ||
|
||
chatwoot = AsyncChatwoot(chatwoot_url=chatwoo_url, access_key=access_key) | ||
|
||
bot = await chatwoot.account_agent_bot.create( | ||
account_id=account_id, | ||
name=name, | ||
description=description | ||
) | ||
return bot | ||
|
||
|
||
async def find_bot_by_name(chatwoo_url: str, | ||
access_key: str, | ||
account_id: int, | ||
name: str) -> Optional[Dict]: | ||
|
||
chatwoot = AsyncChatwoot(chatwoot_url=chatwoo_url, access_key=access_key) | ||
|
||
bots = chatwoot.account_agent_bot | ||
response = await bots.list(account_id=account_id) | ||
|
||
for bot in response.body: | ||
if bot["name"] == name: | ||
return bot | ||
return None | ||
|
||
|
||
async def update_bot(chatwoo_url: str, | ||
access_key: str, | ||
account_id: int, | ||
bot_id: int, | ||
name: str, | ||
description: Optional[str] = None, | ||
webhook_url: Optional[str] = None): | ||
|
||
chatwoot = AsyncChatwoot(chatwoot_url=chatwoo_url, access_key=access_key) | ||
|
||
bot = await chatwoot.account_agent_bot.update( | ||
account_id=account_id, | ||
id=bot_id, | ||
name=name, | ||
description=description, | ||
outgoing_url=webhook_url | ||
) | ||
return bot | ||
|
||
|
||
async def upsert_bot(chatwoo_url: str, | ||
access_key: str, | ||
account_id: int, | ||
name: str, | ||
webhook_url: str, | ||
description: str): | ||
|
||
bot = await find_bot_by_name(chatwoo_url, access_key, account_id, name) | ||
if bot: | ||
log.info(f"Bot {name} already exists. Updating...") | ||
return await update_bot(chatwoo_url, | ||
access_key, | ||
account_id, | ||
bot["id"], | ||
name, | ||
description, | ||
webhook_url) | ||
|
||
log.info(f"Bot {name} does not exist. Creating...") | ||
return await create_account_bot(chatwoo_url, | ||
access_key, | ||
account_id, | ||
name, | ||
description) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
# if __name__ == "__main__": | ||
# import asyncio | ||
# asyncio.run(main()) | ||
|
||
# asyncio.run(create_account_bot(os.environ.get("CHATWOOT_URL"), | ||
# os.environ.get("CHATWOOT_ACCESS_KEY"), | ||
# os.environ.get("CHATWOOT_ACCOUNT_ID"), | ||
# "Ale Test Bot", | ||
# "Bot de prueba para Ale")) | ||
|
||
# res = asyncio.run(find_bot_by_name(os.environ.get("CHATWOOT_URL"), | ||
# os.environ.get("CHATWOOT_ACCESS_KEY"), | ||
# os.environ.get("CHATWOOT_ACCOUNT_ID"), | ||
# "Ale Test Bot")) | ||
|
||
|
||
# res = asyncio.run(update_bot(os.environ.get("CHATWOOT_URL"), | ||
# os.environ.get("CHATWOOT_ACCESS_KEY"), | ||
# os.environ.get("CHATWOOT_ACCOUNT_ID"), | ||
# 73, | ||
# "Ale Test Bot", | ||
# "Bot de prueba para Ale", | ||
# "https://alebot.com/webhook")) | ||
|
||
# print (res) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .woot_lead import WootLead |
Oops, something went wrong.