Creating a Chatbot with Microsoft’s BotBuilder.js and Deploying Using Laravel Forge
Uses
- Microsoft bot framework
- Microsoft Azure bot framework server
- Bot builder JS : https://github.com/microsoft/botbuilder-js
- Generator bot-builder package : https://www.npmjs.com/package/generator-botbuilder
Getting started
This article provides a summary and overview of how I built a bot using BotBuilder.js, the Microsoft Bot Framework, and Laravel Forge.
For a more in-depth guide, you can explore the detailed tutorial by Simon Ågren.
https://www.agrenpoint.com/azurebot-nodejs-part1/
Steps I followed to get started for the first time :
- Install yo and generator
Follow the instructions here to installyo
andgenerator
https://www.npmjs.com/package/generator-botbuilder#installation - Run the command
yo botbuilder
- After it is finished initializing open the newly created folder in vscode and run the command
npm start
- Download Bot emulator from the latest GitHub release https://github.com/microsoft/BotFramework-Emulator/releases
- Install and run the emulator and provide the bot address as : http://localhost:3978/api/messages
DEMO REPO :
https://github.com/pratikkuikel/chatbot-node
Deploying to Custom vps with Laravel forge
- Add new forge site.
- Add daemon process to the server to run node process
`node /home/forge/chat.mydomain.com/index.js` - Edit site’s nginx configuration to proxy requests to node process.
# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/chat.mydomain.com/before/*;
server {
http2 on;
listen 443 ssl;
listen [::]:443 ssl;
server_name chat.mydomai.com;
server_tokens off;
root /home/forge/chat.mydomain.com;
# FORGE SSL (DO NOT REMOVE!)
ssl_certificate /etc/nginx/ssl/chat.mydomain.com/2300349/server.crt;
ssl_certificate_key /etc/nginx/ssl/chat.mydomain.com/2300349/server.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;
ssl_dhparam /etc/nginx/dhparams.pem;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm;
charset utf-8;
# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/chat.mydomain.com/server/*;
location / {
proxy_pass http://localhost:3978; # Proxy requests to Node.js app running on port 3978
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/chat.mydomain.com-error.log error;
error_page 404 /index.html;
location ~ /\.(?!well-known).* {
deny all;
}
}
# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/chat.mydomain.com/after/*;
4. Change forge deployment script to
cd /home/forge/chat.mydomain.com
git pull origin $FORGE_SITE_BRANCH
cd /home/forge/chat.mydomain.com
npm install
# restart node daemon
pkill -f 'node /home/forge/chat.mydomain.com/index.js'
5. Add Messaging endpoint in Azure panel’s bot configuration like :
https://chat.mydomain.com/api/messages
6. Add microsoft azure credentials in .env file, the credentials can be generated or copied from bot settings configuration by clicking on manage password.
MicrosoftAppType=SingleTenant
MicrosoftAppId=xxxx
MicrosoftAppPassword=xxxxx
MicrosoftAppTenantId=xxxxx
7. Add ssl certificate, cloudflare’s can be added. Make sure ssl mode is selected as full in cloudflare.
The final step is to test your bot in Azure’s Web Chat. Best of luck on your chatbot journey!