This project contains an AWS Lambda function and Terraform configuration to create polls about participating in a quiz game in Telegram. The Lambda function sends messages to a Telegram channel, retrieves updates from a connected group, and creates polls based on those updates.
Before you begin, ensure you have the following installed:
quiz-please-poll/
├── src/
│ ├── main.py
│ ├── requirements.txt
│ ├── dependencies
├── terraform/
│ ├── main.tf
│ ├── variables.tf
│ ├── outputs.tf
│ ├── terraform.tfvars
│ └── lambda.zip
├── README.md
-
Clone the repository:
git clone https://github.com/your-repo/telegram-bot-poll-creator.git cd telegram-bot-poll-creator
-
Navigate to the Terraform directory:
cd ../terraform
-
Initialize Terraform:
terraform init
-
Create a
terraform.tfvars
file with the necessary variables. Example:aws_region = "us-east-1" lambda_function_name = "TelegramBotFunction" bot_name = "YourBotName" bot_token = "YOUR_BOT_TOKEN" channel_id = "YOUR_CHANNEL_ID" group_id = "YOUR_GROUP_ID" dynamodb_reg_table_name = "TelegramBotReg" dynamodb_update_table_name = "TelegramBotUpdates" dynamodb_reg_table_arn = "arn:aws:dynamodb:us-east-1:123456789012:table/TelegramBotReg" use_existing_role = true existing_role_name = "lambda_execution_role"
-
Apply the Terraform configuration:
terraform apply
Review the changes and type
yes
to confirm.
The Lambda function uses the following environment variables:
DYNAMODB_REG_TABLE_NAME
: Name of the DynamoDB registration table.DYNAMODB_UPDATE_TABLE_NAME
: Name of the DynamoDB update table.BOT_NAME
: Name of the Telegram bot.BOT_TOKEN
: Token for the Telegram bot.CHANNEL_ID
: ID of the Telegram channel.GROUP_ID
: ID of the Telegram group.
These variables are set in the Terraform configuration and passed to the Lambda function during deployment.
Once deployed, the Lambda function will run every day at 15:00 UTC. It will:
- Load games from the DynamoDB registration table.
- Send a message to the Telegram channel for each game.
- Retrieve recent updates from the connected Telegram group.
- Create a poll in the group based on the updates.
- Update the DynamoDB table with the poll creation status.
Logs for the Lambda function can be viewed in AWS CloudWatch.
This project uses a DynamoDB table with game registration data that should be created separately. Ensure that the TelegramBotReg
table exists and is correctly populated with game registration data before running the Lambda function.
This project is licensed under the MIT License.