Skip to content

Commit

Permalink
feat: add docker support
Browse files Browse the repository at this point in the history
  • Loading branch information
techmovie committed Mar 23, 2023
1 parent ef58e36 commit eef7eef
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 15 deletions.
9 changes: 8 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@ FROM python:3.8
WORKDIR /app

COPY requirements.txt ./
COPY config_sample.py ./config.py
RUN pip install --no-cache-dir -r requirements.txt

ENV NOTION_API_KEY = 'your_notion_api_key'
ENV NOTION_DATABASE_ID = 'your_databse_id'
ENV TELEGRAM_BOT_TOKEN = 'your_telegram_bot_token'
ENV OPENAI_API_KEY = 'your_openai_api_key'
ENV OPENAI_PROMPT = 'your_openai_prompt'

COPY . .

CMD ["python", "main.py"]
CMD ["python", "main.py"]
48 changes: 41 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ A simple Telegram Bot that updates a Notion database based on user input. This b
3. Set up your Notion API key and database ID in `config.py`:

```
NOTION_API_KEY = "your_notion_api_key"
NOTION_DATABASE_ID = "your_notion_database_id"
NOTION_API_KEY = os.environ.get("NOTION_API_KEY", "your_notion_api_key")
NOTION_DATABASE_ID = os.environ.get("NOTION_DATABASE_ID", "your_notion_database_id")
```

4. Set up your Telegram API key in `config.py`:

```
TELEGRAM_API_KEY = "your_telegram_api_key"
TELEGRAM_BOT_TOKEN = os.environ.get("TELEGRAM_BOT_TOKEN", "your_telegram_bot_token")
```

5. Run the bot:
Expand All @@ -37,8 +37,21 @@ A simple Telegram Bot that updates a Notion database based on user input. This b

1. Start a conversation with the bot in Telegram.
2. Use the `/start` or `/help` command to get instructions on how to format your message.
3. Send a message with the specified format to update the Notion database.
3. To use the bot, send a message to it on Telegram in the following format:
```
/update
database_id:your_custom_database_id (optional)
property_name1:value1
property_name2:value2
```
The bot will extract the property names and values from the message and update the specified Notion database accordingly.

If you don't specify a database_id, the bot will use the default one from the configuration file.

Please note that you need to replace `PropertyName1`, `PropertyValue1`, `PropertyName2`, `PropertyValue2`, etc., with the actual property names and values you want to update in the Notion database.

Supported property types: title, rich_text, number, select, multi_select, date, people, files, checkbox, url, email, phone_number

## ChatGPT Usage

Expand All @@ -49,12 +62,12 @@ Follow the steps below to use this feature.
1. Set up your OpenAI API key in `config.py`:

```
OPENAI_API_KEY = "your_openai_api_key"
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY", "your_openai_api_key")
```
2. Set up your prompt in `config.py`:

```
OPENAI_PROMPT = "your_openai_api_prompt"
OPENAI_PROMPT = os.environ.get("OPENAI_PROMPT", "your_openai_api_prompt")
```
In the aforementioned example, the prompt can be:
> Please provide the details of the English word I shared with you and follow this format: Word:\nPronunciation:(Phonetic symbol)\nDefinition:\nIn Chinese:\nExample Sentence:\nDate Learned:(Time when I send this prompt formatted as: YYYY-MM-DD)\nDifficulty:Medium\nRemembered:(Fixed to false)
Expand All @@ -67,4 +80,25 @@ Follow the steps below to use this feature.

4. Send a message starting with the `/openai` command to tell the ChatGPT the things you want to do with the prompt.

In the above example, the message can be: /openai Inclination.
In the above example, the message can be: `/openai Inclination`.

## Commands

* `/start`: Starts the bot and displays a welcome message.
* `/help`: Shows the help message, which contains instructions on how to use the bot and the correct message format.
* `/update`: Triggers the bot to update the Notion database with the properties provided in the message.
* `/openai`: Triggers the bot to update the Notion database with the content generated by ChatGPT.

## Docker

You can also run this project in a Docker container.

```
docker run -e TELEGRAM_API_KEY=your_telegram_api_key -e NOTION_API_KEY=your_notion_api_key -e DATABASE_ID=your_database_id -e OPENAI_API_KEY=your_openai_api_key -e OPENAI_PROMPT=your_openai_prompt birdplane/notion-telegram-bot:latest
```

## Contributing
Feel free to fork this repository and make any changes or improvements you'd like. If you believe your changes could be beneficial to others, please create a pull request, and we'll review your contribution.

## License
This project is licensed under the MIT License.
12 changes: 7 additions & 5 deletions config_sample.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
NOTION_API_KEY = "your_notion_api_key"
NOTION_DATABASE_ID = "your_notion_database_id"
TELEGRAM_API_KEY = "your_telegram_api_key"
OPENAI_API_KEY = "your_openai_api_key"
OPENAI_PROMPT = "your_openai_api_prompt"
import os

NOTION_API_KEY = os.environ.get("NOTION_API_KEY", "your_notion_api_key")
NOTION_DATABASE_ID = os.environ.get("NOTION_DATABASE_ID", "your_notion_database_id")
TELEGRAM_BOT_TOKEN = os.environ.get("TELEGRAM_BOT_TOKEN", "your_telegram_bot_token")
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY", "your_openai_api_key")
OPENAI_PROMPT = os.environ.get("OPENAI_PROMPT", "your_openai_api_prompt")
4 changes: 2 additions & 2 deletions telegram_bot.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import telebot
from config import TELEGRAM_API_KEY
from config import TELEGRAM_BOT_TOKEN
from message_handler import process_message, send_help
from logger import logger
from openai_manager import OpenAiManager

class TelegramBot:
def __init__(self):
self.bot = telebot.TeleBot(TELEGRAM_API_KEY)
self.bot = telebot.TeleBot(TELEGRAM_BOT_TOKEN)

def start(self):
@self.bot.message_handler(commands=['start', 'help'])
Expand Down

0 comments on commit eef7eef

Please sign in to comment.