Створення чат-бота за допомогою Microsoft BotBuilder.js та розгортання через Laravel Forge

pic

Використання

Початок роботи

Ця стаття надає загальний огляд того, як я створив бота, використовуючи BotBuilder.js, Microsoft Bot Framework і Laravel Forge.

Для більш детальної інструкції, ви можете ознайомитися з покроковим посібником від Simon Ågren.

https://www.agrenpoint.com/azurebot-nodejs-part1/

Кроки, які я виконав для початку роботи:

  1. Встановіть yo і generator
    Дотримуйтесь інструкцій тут, щоб встановити yo та generator https://www.npmjs.com/package/generator-botbuilder#installation
  2. Запустіть команду yo botbuilder
  3. Після завершення ініціалізації відкрийте новостворену папку у vscode та запустіть команду npm start
  4. Завантажте Bot emulator з останнього релізу на GitHub https://github.com/microsoft/BotFramework-Emulator/releases
  5. Встановіть і запустіть емулятор, вказавши адресу бота: http://localhost:3978/api/messages

ДЕМО РЕПОЗИТОРІЙ:

https://github.com/pratikkuikel/chatbot-node

Розгортання на власному VPS за допомогою Laravel Forge

  1. Додайте новий сайт на Forge.
  2. Додайте процес демона на сервер для запуску процесу Node
    node /home/forge/chat.mydomain.com/index.js
  3. Змініть конфігурацію nginx для проксінгу запитів до процесу Node.js.
# 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; # Проксі запити до Node.js програми, що працює на порту 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/*;
  1. Змініть скрипт розгортання на Forge на
cd /home/forge/chat.mydomain.com  
git pull origin $FORGE_SITE_BRANCH  

cd /home/forge/chat.mydomain.com  
npm install  

# перезапуск процесу Node  
pkill -f 'node /home/forge/chat.mydomain.com/index.js'

5.
Додайте точку кінцевого повідомлення в панелі Azure для конфігурації бота, як-от:
https://chat.mydomain.com/api/messages

  1. Додайте облікові дані Microsoft Azure у файл .env, ці дані можна згенерувати або скопіювати з налаштувань бота, натиснувши на "управління паролем".
MicrosoftAppType=SingleTenant  
MicrosoftAppId=xxxx  
MicrosoftAppPassword=xxxxx  
MicrosoftAppTenantId=xxxxx
  1. Додайте SSL сертифікат, можна використовувати сертифікати Cloudflare. Переконайтесь, що в Cloudflare обрано режим SSL як "Full".

Останній крок — протестуйте вашого бота у Web Chat на Azure. Бажаю удачі у вашій подорожі з чат-ботом!

Перекладено з: Creating a Chatbot with Microsoft’s BotBuilder.js and Deploying Using Laravel Forge

Leave a Reply

Your email address will not be published. Required fields are marked *