A bot service for health survey implemented by Cisco Webex and AWS.
Serverless Framework is used as a deployment tool.
https://www.serverless.com/
Public Cloud Provider: AWS
Function Runtime: Python3.8
All Python scripts in this application do not use any external libraries except standard libraries that are included in the Lambda Python 3.8 runtime. You don't need to include any additional modules into the Lambda package.
You need a linux instance to deploy.
CentOS Linux release 7.5.1804 (Core)
To use Serverless Framework, you need to install Node.js on your linux instance for deployment.
# nvm(Node.js version management tool) Run the installation script curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash source ~/.bashrc # Node.js + npm Install nvm install --lts nvm use --lts # Confirm the version node -v
npm install -g serverless
Create a AWS IAM user with the 'AdministratorAccess' policy referring to the AWS document bellow:
Creating your first IAM admin user and group
Get access keys for the IAM user.
Managing access keys for IAM users
Set up credentials in your instance to execute Serverless Framework CLI.
serverless config credentials --provider aws --key {IAM USER ACCESS KEY} --secret {IAM USER SECRET KEY} # Confirm cat ~/.aws/credentials
cd {Working Directory} git clone {Repository URL} cd health-survey-bot
serverless.yml is a Serverless Framework configuration file. In the 'environment' section of this file, you need to set some environment variables which will be passed to the Lambda execution environment.
The parameters that need to be prepared are as follows
Notes:
... # Provider, Function Runtime provider: name: aws runtime: python3.8 # Set environment variables that are deployed in the Lambda runtime environment environment: # An access token for Cisco Webex Bot that submits a health survey confirmation form. CISCO_WEBEX_ACCESS_TOKEN: <Webex Bot access token> # S3 bucket name to save past answer results S3_BUCKETNAME: <BUCKETNAME> # DynamoDB table name to save answer results (default is service name) DYNAMODB_TABLENAME: ${self:service}-${self:provider.stage} # TimeZone TZ: 'UTC' # logging level LOG_LEVEL: INFO ...
card_settings.json is a configuration file for the question form sent to the recipients. You can change the messages in the survey card by modifying this file.
Defaults are as follows:
{ "title": "COVID-19 Measures Health Survey", "description":"It is request from the COVID-19 Countermeasures Headquarters. Please answer the following questions to ensure your safety.", "questions": [ { "title": "Please let us know your current physical condition*", "choices": [ { "title": "Good", "value": "false" }, { "title": "Poor physical condition", "value": "true" } ] }, { "title": "Please let us know about the physical condition of your roommate*", "choices": [ { "title": "All good", "value": "false" }, { "title": "Some people are poor condition", "value": "true" } ] } ] }
organizations.json is an organization setting file.
You can add the above sets of attributes in dictionary format as many as you need.
In order to run this application, you need to add one or more existing Webex accounts to the 'users' and 'admins' list.
[ { "name": "OrgA", "admins": [ "a-admin@netone.local", "admin@netone.local" ], "users": [ "a-user1@netone.local", "a-user2@netone.local", "a-user3@netone.local" ] }, { "name": "OrgB", "admins": [ "b-admin@netone.local" ], "users": [ "b-user1@netone.local", "b-user2@netone.local", "b-user3@netone.local" ] } ] ...
All required AWS resource will be created with Serverless Framework CLI.
sls deploy
Staging allows you to create multiple environments.
If the stage is omitted, it will be same as follows.
sls deploy --stage=dev
You only need to register for a Cisco Webex webhook after the initial deployment.
sls invoke -f create_webhook
sls remove
This is the default specification for each resource which will be created after you execute the 'sls deploy' command.
Each setting can be changed in the 'serverless.yml'configuration file.
"{stage}" changes depending on the value of the --stage option at the time of deployment.
Amazon API Gateway, AWS Lambda, Amazon Dynamo DB, and Amazon S3 may be billed based on usage.
Please refer the AWS page for details: AWS Free Tier
health-survey-{stage}-sender
# serverless.yml ... # Set in -9 hours considering JST TZ +0900 - schedule: cron(0 0 ? * * *) ...
health-survey-{stage}-reciever
health-survey-{stage}-status
# serverless.yml ... - schedule: cron(0 3 ? * * *)
health-survey-{stage}-create_webhook
Code Exchange Community
Get help, share code, and collaborate with other developers in the Code Exchange community.View Community