This is a sample implementation of LINE Bot that detects labels on sent images by Amazon Rekognition.
- User sends a picture to the Bot
- LINE server make a callback request to the associated endpoint
- Amazon API Gateway invokes the associated AWS Lambda function
- AWS Lambda validates the request, and then enqueues the payload into Amazon SQS
- Responsing 200 OK
- Ditto
- Invoking the function triggered by SQS events
- Download the image that user sent from LINE server
- Calling the detect label API of Amazon Rekognition
- Replying the labels of the sent image
- Python 3.6+
- The implementation contains,
- type hinting
- f-string
- The implementation contains,
- AWS Chalice
- LINE Messaging API SDK for Python
https://developers.line.biz/en/services/messaging-api/
You need to sign up and register your API via the site above.
And take a copy of channel secret
and channel access token
.
Install and configure AWS CLI referring the following guides.
AWS Chalice depends on the credential settings configured by the procedre.
- https://docs.aws.amazon.com/en_pv/cli/latest/userguide/cli-chap-install.html
- https://docs.aws.amazon.com/en_pv/cli/latest/userguide/cli-chap-configure.html
Create Amazon SQS queue, and take a copy of its queue name.
Note that the visivility timeout of the queue have to be more than 60, otherwise the queue cannot integrate with AWS Lambda function.
This sample project has an example configuration file.
You need to copy (or rename) the file and configure appropriately.
$ cp .chalice/config.json.exapmle .chalice/config.json
$ cat .chalice/config.json
{
"version": "2.0",
"app_name": "LINEBotWorkshop",
"autogen_policy": false,
"iam_policy_file": "policy.json",
"stages": {
"dev": {
"api_gateway_stage": "api",
"environment_variables": {
"SQS_QUEUE_NAME": "",
"LINE_CHANNEL_SECRET": "",
"LINE_CHANNEL_ACCESS_TOKEN": ""
}
}
}
}
Activate the virtual environment as needed before performing this procedure
$ pip install requirements.txt
Once dependencies are successfully installed, you can run chalice deploy
command
$ chalice deploy
This library is licensed under the MIT-0 License. See the LICENSE file.