Building a Telegram Bot with AWS API Gateway and AWS Lambda

Опубликовано: 04 Октябрь 2024
на канале: Knowledge Amplifier
8,440
151

This video demonstrate making a simple serverless Telegram bot that can shorten a Long URL, using AWS API Gateway and AWS Lambda.

Prerequisite:
-----------------------
In-depth intuition on Webhooks-Push-Styled API with Hands-On Demo
   • In-depth intuition on Webhooks-Push-S...  
Build a Github Webhook handler with API Gateway & AWS Lambda
   • Build a Github Webhook handler with A...  

Documentation for cleanuri API:
--------------------------------------------------------
https://cleanuri.com/docs

To Steup Webhook for Telegram Bot:
-------------------------------------------------------------------
https://api.telegram.org/bot{HTTP Token}/setWebhook

Code:
-----------------

import json
import requests

def lambda_handler(event, context):
print(event)
try:
body=json.loads(event['body'])

print(body)


message_part=body['message'].get('text')
print("Message part : {}".format(message_part))

data = {'url': message_part}

payload=requests.post('https://cleanuri.com/api/v1/shorten',...)
short_url=payload.json()['result_url']
print("The short url is : {}".format(short_url))

chat_id=body['message']['chat']['id']

url = f'https://api.telegram.org/bot{HTTP Token}/sendMessage'
payload = {
'chat_id': chat_id,
'text': short_url
}

r = requests.post(url,json=payload)

return {
"statusCode": 200
}
except:
return {
"statusCode": 200
}


Check this playlist for more Data Engineering related videos:
   • Demystifying Data Engineering with Cl...  

Snowflake Complete Course from scratch with End-to-End Project with in-depth explanation--
https://doc.clickup.com/37466271/d/h/...

🙏🙏🙏🙏🙏🙏🙏🙏
YOU JUST NEED TO DO
3 THINGS to support my channel
LIKE
SHARE
&
SUBSCRIBE
TO MY YOUTUBE CHANNEL