Skip to content

Commit

Permalink
#5 solution to deploy to aws as a lambda with a webhook - not working…
Browse files Browse the repository at this point in the history
… yet
  • Loading branch information
Oleksandr Gavryliuk committed Dec 7, 2023
1 parent 68eddfb commit 0cba266
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 5 deletions.
29 changes: 24 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
.idea
*.iml

venv
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
.venv
.env

# Serverless directories
.serverless

#Intellij IDEA files
.idea
*.iml
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,19 @@

name: daily-dragon
username: daily_dragon_bot

To deploy with `serverless`:

```serverless deploy --aws-profile havryliuk```

The response will show you the webhook url. Set up a webhook:

```curl --request POST --url https://api.telegram.org/bot<TOKEN>/setWebhook --header 'content-type: application/json' --data '{"url": "https://u3ir5tjcsf.execute-api.us-east-1.amazonaws.com/dev/my-custom-url"}'```

To undeploy:

```serverless remove --aws-profile havryliuk```

Use this article if available:

https://medium.com/hackernoon/serverless-telegram-bot-on-aws-lambda-851204d4236c
28 changes: 28 additions & 0 deletions handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import logging
from dotenv import load_dotenv
import os

from telegram import Update
from telegram.ext import ApplicationBuilder, ContextTypes, CommandHandler

logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO
)

load_dotenv()
TOKEN = os.getenv('TOKEN')
if TOKEN is None:
raise ValueError('TOKEN not found in .env file')


async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
await context.bot.send_message(chat_id=update.effective_chat.id, text="Hello! I am 每日龙!\nLauching soon!")

if __name__ == '__main__':
application = ApplicationBuilder().token(TOKEN).build()

start_handler = CommandHandler('start', start)
application.add_handler(start_handler)

application.run_polling()
20 changes: 20 additions & 0 deletions serverless.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
service: daily-dragon

provider:
name: aws
runtime: python3.11
stage: dev
region: us-east-1
environment:
TELEGRAM_TOKEN: ${env:TELEGRAM_TOKEN}



functions:
post:
handler: handler.py
events:
- http:
path: daily-dragon
method: post
cors: true

0 comments on commit 0cba266

Please sign in to comment.