This is a sample template for Dialogflow chatbot.
It consists of
- AWS SAM script for package and deploy AWS Lambda function for Dialogflow fulfillment
- Express server to proxy AWS Lambda and dialogflow-fulfillment library
- Dialogflow fulfillment agent
Below is a brief explanation of what we have generated for you:
.
├── README.MD <-- This instructions file
├── event.json <-- API Gateway Proxy Integration event payload
├── aws <-- Scripts for AWS CloudFormation
│ └── template.yaml <-- Source code for a lambda function
│
├── scripts
│ └── sam-deploy.sh <-- Shell script to deploy for each environment
│ └── sam-package.sh <-- Shell script to package for each environment
│
├── chatbot <-- Source code for a lambda function
│ └── dialogflow <-- Source code for Dialogflow chatbot fulfillment
│ └── constant <-- Constant scripts
│ └── entity <-- Entity scripts
│ └── intent <-- Intent scripts
│ └── mapping <-- Mapping scripts (interface to external data source)
│ └── services <-- Services (controllers)
│ └── utils <-- Utilities
│ └── mainChat.js <-- Main script for Dialogflow Agent
│
│ └── tests <-- Unit tests
│ └── unit
│ └── test-handler.js <-- Test scripts here
│
│ └── app.js <-- Express server to proxy AWS Lambda to dialogflow-fulfillment library
│ └── package.json <-- NodeJS dependencies and scripts
│ └── .npmignore <-- NPM ignore script
│
├── .gitignore <-- SAM template
├── template.yaml <-- SAM template- AWS CLI already configured with Administrator permission
- NodeJS 8.10+ installed
- Docker installed
Invoking function locally using a local sample payload
sam local invoke ChatbotFunction --event event.jsonInvoking function locally through local API Gateway
sam local start-apior skip pulling Docker image
sam local start-api --skip-pull-imageIf the previous command ran successfully you should now be able to hit the following local endpoint to invoke your function http://localhost:3000/fulfillment
We use mocha for testing our code and it is already added in package.json under scripts, so that we can simply run the following command to run our tests:
cd chatbot
yarn
yarn testPackage the Lambda function
./scripts/sam-package.sh <environment>Deploy the Lambda function
./scripts/sam-deploy.sh <environment>