This is a line chatbot demo code running on AWS lambda which calling AWS translate service in background. You might be charged by AWS and please check AWS free-tier servides. You might be also charged by Line business account and please refer to Line Offical website for details.
- need to enable your line developer account
- need to add your webhook url - this is your api gateway URL
- need to install serverless framework
- need to install aws cli and export your
- gin gonic web framework
- line-bot-sdk-go
- aws-go-sdk
go get -u github.com/apex/gateway go get -u github.com/line/line-bot-sdk-go/linebot go get -u github.com/gin-gonic/gin go get -u github.com/webbhlin/awstranslate
export AWS_ACCESS_KEY_ID= export AWS_SECRET_ACCESS_KEY=
serverless create -t aws-go-dep -p go-linechatbotlambda
if you use serverless command to create your project, your main.go should be under /hello. This is also what I use for this demo, and you are feel to change but require to update your serverless.yml file.
In your terminal:
- copy the main.go file to your project by typeing "cp main.go to_your_serverless_project/hello/"
- compile the go binary by typeing "make" - ensure your check your Makefile. Please check my Makefile sample.
- fix the errors if any. do you go get all the library you need? any typo?
- if there is no error, congrats~ you are free to go next and try "sls deploy"
sls deploy
It might take 3-5 minutes to be ready after you implement your lambda function. In the line console, you have to update your webhook url by clicking "edit" button and test the webhook by clicking on "verify"
You will see a success message in a pop window of line console. If you don't see the success message, go to your cloudwatch log to see what happened.
endpoints: POST - https://xxxxx.execute-api.us-east-2.amazonaws.com/dev/hello
Translating English to Traditional Chinese by AWS translate service
'2tw hello, I like to say hello!'
Translating Tranditional Chinese to English by AWS translate service
'2en 你是在哈囉嗎?'
Command helper
'@@'
https://www.youtube.com/embed/nTyU3pXkN_Q
serverless.yml guideline - https://www.serverless.com/framework/docs/providers/aws/guide/functions/
linechatbot sample code - https://github.com/kkdai/LineBotTemplate/blob/master/main.go
serverless golang examples - https://www.serverless.com/blog/framework-example-golang-lambda-support/
gin gonic github - https://github.com/gin-gonic
gin-lambda github - https://github.com/appleboy/gin-lambda
serverless examples [very useful] - https://github.com/serverless/examples