The program provides a HTTP API endpoint to receive kinds of dingtalk callback events and persist them in AWS DynamoDB, including BPM events, Organization events and so on.
It is written by Kotlin and leverages below AWS services,
- Get the corpid of your dingtalk's organization in open dev platform
- Create secure parameters named
DD_TOKEN,DD_AES_TOKENandDD_CORPID(from step 1) in Systems Manager - Create a S3 bucket(say
my-deploy-bucket) for deployment - [Optional] Install and configure SAM CLI for local deployment
# build the source
./gradlew build# package the lambda functions
sam package --output-template-file packaged.yaml \
--s3-bucket my-deploy-bucket --template-file template-sam.yaml
# deploy the lambda function, api gateway, dybnamodb
sam deploy --template-file ./packaged.yaml \
--stack-name my-dingtalk-callback --capabilities CAPABILITY_IAMDeploy via serverless framework
sls deploy- Put the github person token to
codepipeline.json - Set the s3 bucket name in
codepipeline.json - Set any parameter in
codepipeline.jsonif necessary, such as app name, repo name and branch name - Create a CI/CD pipeline in CodePipeline via below command, which can be continously triggered by new commits of this repo then deploy lambda HTTP endpoint
aws cloudformation create-stack --stack-name dingtalk-mycorp --template-body file://codepipeline.yml --parameters file://codepipeline.json --capabilities CAPABILITY_NAMED_IAM- Get
id of api gateway of AWScreated by above deployment - Use dingtalk API to register/update this serverless API gateway endpoint as callback of dingtalk events.
For example,
curl -X POST \
'https://oapi.dingtalk.com/call_back/update_call_back?access_token=<your token>' \
-H 'Content-Type: application/json' \
-d '{
"call_back_tag": [
"bpms_task_change",
"bpms_instance_change"
],
"token": "<token created in prerequisites step 2>",
"aes_key": "<aes token created in prerequisites step 2>",
"url": "https://<id of api gateway created by above deployment>.execute-api.<your region>.amazonaws.com/v1/dingtalk"
}'
I also port this lambda function to use Spring Cloud Function as lambda framework, you can checkout this branch if your're interested.