This project helps you setup a Telegram bot that runs on AWS Lambda and takes a text message and replies with an audio file of that message generated by AWS Polly.
This project uses yagop's node telegram bot api and lesterchan's telegram bot and aws lambda guide.
The AWS API version is locked to 2016-06-10
.
$ git clone https://github.com/marcusmolchany/polly-telegram-bot.git
$ cd polly-telegram-bot
$ npm install
Once your bot is running it will respond to commands of the following two formats:
- Any text message
- A text message that starts with the slash command of the name of a Polly voice. For example:
/Nicole Hello there
.
The list of supported AWS Polly voices is in voice-ids.js
.
"The arsonist had oddly shaped feet."
"/Nicole hello there."
"/Brian good morning."
"/Celine quoi de neuf?"
Follow the steps outlined in lesterchan's telegram bot guide to:
- create a Telegram Bot using BotFather
- create an AWS Lambda function through the AWS Console
- connect your Lambda function with an API Gateway through the AWS Console
- set your telegram webhook
Instead of cloning lesterchan's repository you will use this one for the code in your lambda function.
You will need to use this command from his setup to generate a zip file of your project to upload to your AWS Lambda function (the generated file is git ignored):
$ zip -r telegram-bot.zip *.js node_modules/*
Copy token.sample.js
into token.js
. Copy the Telegram bot token given to you by BotFather and
replace the text YOURTELEGRAMBOTTOKEN
with your bot token. token.js
is git ignored.
$ cp token.sample.js token.js
Configure access keys following this guide.
You will need the access keys AmazonS3FullAccess
and AmazonPollyFullAccess
set for your user.
Copy creds.sample.js
into creds.js
and store your accessKeyId
and secretAccessKey
into
the credentials
object. creds.js
is git ignored.
Set your region
to whichever region your lambda function is running from.
$ cp creds.sample.js creds.js
Navigate to S3 in the AWS Console, make sure you're in the same region as where you created your Lambda function. Create a new bucket to store your generated Polly files.
Copy constants.sample.js
into constants.js
. Change the value of s3.bucketName
to the name
of your S3 bucket.
$ cp constants.sample.js constants.js
https://github.com/aws/aws-sdk-js
http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS.html
http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Polly.html
https://trevorsullivan.net/2016/12/01/amazon-aws-cloud-polly-nodejs/
http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html
http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/s3-example-creating-buckets.html
https://github.com/awslabs/aws-nodejs-sample/blob/master/sample.js