botbook/site/docs/chapter-06-gbapp-reference.md

571 lines
20 KiB
Markdown
Raw Normal View History

---
sidebar_position: 60
---
# .gbapp Reference
2020-10-02 09:24:18 -03:00
![generalbots-2018](https://user-images.githubusercontent.com/65977273/94922431-949c3900-0490-11eb-800a-6b478d689f2a.png)
2019-03-01 15:34:29 -03:00
## Introduction
.gbapp is the folder extension for the General Bots Application package type.
Anything inside a folder considered a .gbapp will be consumed by the server
like a TypeScript application. This conversational application will contain
the source code for custom dialogs and behaviour for any .gbot that associate
this deployed .gbapp.
A good way to start a .gbapp is to find a NPM package to create a .gbapp that
asks for data and output the result. For example, a temperature package can
be installed via `npm install temperature` and then have its methods
convertToKelvin or convertToCelsius called when user asks for conversion. A
.gbapp can persist and read data from database according to the conversation
session.
2023-01-28 09:57:45 -03:00
Please read: [Anti Patterns Catalog](http://wiki.c2.com/?AntiPatternsCatalog).
2019-03-01 15:34:29 -03:00
## Preparing Environment
2021-07-18 09:33:27 -03:00
General procedures:
1. Get SubscriptionId, username and password;
2. Create AppId and Secret;
2023-01-02 10:13:15 -03:00
3. Agree to MSFT [Responsible AI #1](https://portal.azure.com/#view/Microsoft_Azure_ProjectOxford/TextAnalyticsCreate_Dx/searchEnabled~/false/storageEnabled~/false/dxParameters~/%7B%22searchEnabled%22%3Afalse%2C%22storageEnabled%22%3Afalse%7D) and [Responsible AI #2](https://portal.azure.com/#create/Microsoft.CognitiveServicesAllInOne);
2023-03-01 15:24:22 -03:00
4. Deploy General Bots;
2023-12-20 14:11:56 -03:00
5. In Application | Permissions:
2023-12-20 13:58:19 -03:00
- Microsoft Graph
- Sites.Read.All
- Sites.ReadWrite.All
- User.Read
- Application.Read.All
- Application.ReadWrite.All
6. In Authentication | Add Platform | Web | Redirect URL: https://server/botId/token;
2023-12-20 13:57:44 -03:00
6. /setupSecurity to get access to Bot Drive (Clean: https://www.domstamand.com/removing-user-consent-from-an-azure-ad-application/);
7. /publish to publish packages on root bot.
2021-07-18 09:33:27 -03:00
2024-01-20 14:24:19 -03:00
## .env
.env is generated automatically, but if you want to advance, editing by yourself, put this file, filled, at BotServer root:
```
BOT_ID=
CLOUD_SUBSCRIPTIONID=
CLOUD_LOCATION=
CLOUD_GROUP=
CLOUD_USERNAME=
CLOUD_PASSWORD=
MARKETPLACE_ID=
MARKETPLACE_SECRET=
```
2019-03-01 15:34:29 -03:00
### Windows
2019-11-11 12:24:06 -03:00
#### PowerShell Script
2022-10-19 11:27:29 -03:00
Copy and paste on a PowerShell prompt with elavated privileges and when VSCode is opened just press F5 to run the development server.
2023-01-05 09:31:31 -03:00
Please ensure that Node.js is not installed and enter your Source Directory.
2019-11-11 12:24:06 -03:00
2020-06-11 09:48:42 -03:00
``` powershell
2019-11-11 12:24:06 -03:00
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
2023-08-03 14:24:57 -03:00
choco install git --confirm
choco install nodejs --confirm --version=19.3.0
choco install vscode --confirm
2022-12-29 17:02:57 -03:00
2019-11-11 12:24:06 -03:00
&"C:\Program Files\Git\bin\git.exe" clone https://github.com/GeneralBots/BotServer.git
cd BotServer
2023-08-03 14:27:08 -03:00
code .
2019-11-11 12:24:06 -03:00
2023-01-05 09:31:31 -03:00
#### Python & GCC
Install Python: https://www.python.org/downloads/release/python-2718/
npm install windows-build-tools -g
npm install -g node-gyp
2019-11-11 12:24:06 -03:00
```
2020-06-11 09:48:42 -03:00
2021-11-22 08:21:11 -03:00
### Linux (Ubuntu)
2021-11-23 07:38:19 -03:00
Visual Studio Code
2021-11-22 08:22:54 -03:00
```
2024-08-29 22:35:27 -03:00
apt update
apt install software-properties-common apt-transport-https wget
wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | apt-key add -
add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main"
apt update
apt install code
2022-07-23 15:47:33 -03:00
2021-11-22 08:22:54 -03:00
```
2021-11-22 08:21:11 -03:00
Node JS 20
2021-11-22 18:58:12 -03:00
```
2021-11-23 08:05:16 -03:00
2024-08-29 22:35:27 -03:00
curl -fsSL https://deb.nodesource.com/setup_20.x | -E bash -
apt-get install -y nodejs
2021-11-23 07:38:19 -03:00
node -v
2024-08-29 22:35:27 -03:00
apt install npm
2021-11-23 08:07:39 -03:00
npm -v
2021-11-22 18:58:12 -03:00
```
2021-11-22 08:21:11 -03:00
2023-12-20 18:53:20 -03:00
Opening 443 Port in Linux
```
2024-08-29 22:35:27 -03:00
setcap 'cap_net_bind_service=+ep' $(readlink -f $(which node))
2023-12-20 18:55:20 -03:00
2023-12-20 18:53:20 -03:00
```
2022-10-25 09:40:39 -03:00
Additional Infrastructure
2022-10-17 17:55:00 -03:00
```
2024-08-29 22:35:27 -03:00
apt-get install cpulimit
sudo apt-get install expect
apt-get install libxtst-dev
2022-10-17 17:55:00 -03:00
apt-get install libpng-dev
2024-08-29 22:35:27 -03:00
apt-get install python g++ build-essential
2022-10-17 18:02:57 -03:00
npm install -g node-gyp
2022-10-17 17:55:00 -03:00
```
2023-02-20 00:51:47 -03:00
Add export GTK_IM_MODULE="xim" to .profile to fix Key Bindings in VSCode on Ubuntu.
2022-10-25 09:40:39 -03:00
### Setup git
2022-10-17 17:55:00 -03:00
2022-10-25 09:40:39 -03:00
```
git config --global user.name "Your Name"
git config --global user.email "someone@domain.com"
```
2022-10-17 17:55:00 -03:00
2020-10-05 13:19:25 -03:00
### Commands to check version of Node.js and NPM.
![verificar](https://user-images.githubusercontent.com/65977273/95104867-bace0d00-070c-11eb-9699-66d3b6134ea5.png)
2019-11-11 12:24:06 -03:00
#### Manual steps.
2020-09-23 10:21:13 -03:00
1. Install [Chocolatey](https://chocolatey.org/install), a Windows Package Manager;
2. Install [git]( `https://git-scm.com/` ), a Software Configuration Management (SCM) and TortoiseGit;
2020-06-11 09:48:42 -03:00
3. Install [Node.js](https://npmjs.com/get-npm), a [Runtime system](https://en.wikipedia.org/wiki/Runtime_system);
2019-03-01 15:34:29 -03:00
4. Install Visual Studio Code Insiders, Brackets or Atom as an editor of your choice;
5. Fork the repository by visiting https://github.com/pragmatismo-io/BotServer/fork;
6. Clone the just forked repository by running `git clone your-forked-repository-url/BotServer.git` ;
2020-06-11 09:48:42 -03:00
7. Run the bot server by `gbot.cmd` .
2019-03-01 15:34:29 -03:00
2021-11-06 08:51:11 -03:00
#### Common Errors
- The subscription is not registered to use namespace 'Microsoft.Web'. See https://aka.ms/rps-not-found for how to register subscriptions.
-- Enter Azure | Subscription | Resource providers | Find Microsoft.Web and check it.
2021-11-06 08:51:11 -03:00
2019-08-21 08:50:47 -03:00
* Required packages
2019-03-01 15:34:29 -03:00
2020-06-11 09:48:42 -03:00
``` cmd
2019-03-01 15:34:29 -03:00
cinst git --confirm
cinst nodejs --confirm
2020-04-25 22:48:51 -03:00
npm install windows-build-tools -g
2020-09-23 10:21:13 -03:00
cinst tortoisegit --confirm
2019-08-21 08:50:47 -03:00
```
* Optional packages
2020-06-11 09:48:42 -03:00
```
2019-03-01 15:34:29 -03:00
cinst 7zip.install --confirm
cinst tortoisegit --confirm
cinst winscp --confirm
cinst sysinternals --confirm
cinst putty --confirm
cinst pandoc --confirm
cinst curl --confirm
cinst micro --confirm
cinst ccleaner --confirm
cinst notepadplusplus --confirm
cinst sql-server-management-studio --confirm
```
2019-08-21 08:50:47 -03:00
* node packages
2020-06-11 09:48:42 -03:00
```
2019-08-21 08:50:47 -03:00
npm install -g npm-check-updates
2020-11-22 12:42:31 -03:00
npm install -g cost-of-modules
2019-08-21 08:50:47 -03:00
```
2021-12-10 15:23:29 -03:00
Linux
```
# MS Remote Desktop Connection (RDP Client)
2024-08-29 22:35:27 -03:00
apt-add-repository ppa:remmina-ppa-team/remmina-next
apt update
apt install remmina remmina-plugin-rdp remmina-plugin-secret
2021-12-10 15:23:29 -03:00
```
2022-01-14 08:46:40 -03:00
# File compression
```
Compressing a directory in Linux:
tar -cvzf my_archive.tar.gz input_dir
Expanding an archive in Linux:
tar -xf my_archive.tar.gz
```
2023-07-28 08:57:05 -03:00
# Removing Node.js on Linux
2024-02-14 16:50:58 -03:00
```
2024-08-29 22:35:27 -03:00
rm -rf /usr/local/bin/npm
rm -rf /usr/local/share/man/man1/node*
rm -rf /usr/local/lib/dtrace/node.d
rm -rf ~/.npm
rm -rf ~/.node-gyp
rm -rf /opt/local/bin/node
rm -rf opt/local/include/node
rm -rf /opt/local/lib/node_modules
rm -rf /usr/local/lib/node*
rm -rf /usr/local/include/node*
rm -rf /usr/local/bin/node*
2024-02-14 16:50:58 -03:00
```
2019-03-01 15:34:29 -03:00
![General Bots Inside Visual Studio Code provides a complete artificial intelligence based conversational platform](https://raw.githubusercontent.com/pragmatismo-io/BotServer/master/docs/images/general-bots-inside-visual-studio-code-provides-a-complete-artificial-intelligence-based-conversational-platform.png)
## Specifications
## Dialogs
The dialog is built by specifing series of methods, disposed as an array as seen
on Figure 1. Each dialog has also an identifier that can be called by several
engines like kb.gbapp, which handles cloud based search for documents and other
knowledge base information and also routes for the natural language processing
(NLP) engine.
2020-06-11 09:48:42 -03:00
``` typescript
2019-03-01 15:34:29 -03:00
static getDialogs(bot: BotAdapter, min: GBMinInstance) {
return [{name:"/convertTemperature", waterfall: [
async step => {
},
async step => {
},
async step => {
}]
},{name:"/convertCurrency", waterfall: [
async step => {
},
async step => {
},
async step => {
}]
}
]
```
*Figure 1 - How to build dialogs in General Bots using TypeScript*
2020-09-30 15:30:38 -03:00
## Fork concept
2020-09-30 15:31:10 -03:00
Is the implementation of new software based on existing software. The branch takes advantage of the data already used in other software to generate a new one.
2020-10-07 10:40:13 -03:00
This in some way contributes to a better understanding of how it works.
2020-09-29 10:16:35 -03:00
## How To...
2024-04-12 20:04:30 -03:00
### Clean up bot directly on database
@@id = 0
DELETE FROM GuaribasConversationMessage WHERE instanceId = @id
DELETE FROM GuaribasConversation WHERE instanceId = @id
DELETE FROM GuaribasUser WHERE instanceId = @id
DELETE FROM GuaribasAnswer WHERE instanceId = @id
DELETE FROM GuaribasQuestion WHERE instanceId = @id
DELETE FROM GuaribasPackage WHERE instanceId = @id
2020-09-29 10:16:35 -03:00
2023-02-03 18:52:01 -03:00
### Create a new keyword
- 10min. Find the package on npmjs.com;
- 2min. Perform keywords list update;
- (Optional) 10min. Create a new facade of keywords (Create service file, add reference to package/index.ts, and make a call);
- 20min. Keyword code call and infrastructure to support it.
2020-09-29 10:16:35 -03:00
### Debugging .gbapp deployed on Azure
1. Visit https://SITENAME.scm.azurewebsites.net/api/vfs/LogFiles/Application/index.html
2020-09-29 10:16:35 -03:00
2022-12-23 08:41:29 -03:00
## Commit code
2023-01-02 09:33:44 -03:00
See https://semver.org/.
2023-01-02 09:32:02 -03:00
2023-01-02 10:35:28 -03:00
The numbering rules are defined as the following syntax:
1.0.0
MAJOR.MINOR.PATCH
(BREAK.FEATURE.BUG)
2023-01-02 09:32:02 -03:00
2023-01-02 10:35:28 -03:00
### Details
2023-01-02 09:32:02 -03:00
2023-01-02 10:35:28 -03:00
- A fix in the code (0.0.*1*):
2023-01-02 09:32:02 -03:00
2023-01-02 09:33:44 -03:00
```
fix(azuredeployer.gbapp): stop graphite breaking when too much pressure applied Patch Fix Release
```
2023-01-02 09:32:02 -03:00
2023-01-02 10:35:28 -03:00
- A new feature (0.*1*.0):
2023-01-02 09:32:02 -03:00
2023-01-02 09:33:44 -03:00
```
feat(core.gbapp): add 'graphiteWidth' option
```
2023-01-02 10:35:28 -03:00
- A commit incrementing main version number (*1*.0.0):
2023-01-02 09:33:44 -03:00
```
BREAKING CHANGE: The graphiteWidth option has been removed.
```
2023-01-02 10:35:28 -03:00
- A commit without incrementing version number (version remains unchanged)
2023-01-02 09:33:44 -03:00
```
perf(core.gbapp): Improved loop.
```
2023-01-02 10:35:28 -03:00
2023-01-02 09:33:44 -03:00
### Rules
2023-01-02 09:34:37 -03:00
- BREAK: If the body contains the text “BREAKING CHANGE” then MAJOR version is incremented.
- FEATURE: If the type contains feat/feature, then MINOR version is incremented.
- BUG If the type contains fix, then PATCH version is incremented.
2023-01-02 09:33:44 -03:00
2023-02-07 10:50:18 -03:00
### Types
build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
ci: Changes to our CI configuration files and scripts (examples: CircleCi, SauceLabs)
docs: Documentation only changes
feat: A new feature
fix: A bug fix
perf: A code change that improves performance
refactor: A code change that neither fixes a bug nor adds a feature
test: Adding missing tests or correcting existing tests
Sources:
- https://medium.com/agoda-engineering/automating-versioning-and-releases-using-semantic-release-6ed355ede742
- https://github.com/angular/angular/blob/main/CONTRIBUTING.md#-commit-message-format (Types)
2019-03-01 15:34:29 -03:00
## Tooling
### JavaScript
2020-06-11 09:48:42 -03:00
| Título | Endereço |
|---------------------------------------------|---------------------------------------------------------------------------------------------------|
| | https://deeplearnjs.org/ |
| | Oimo.js http://lo-th.github.io/Oimo.js/\#stacking |
| | js-sequence-diagrams: https://bramp.github.io/js-sequence-diagrams/ |
| | http://blog.avenuecode.com/a-library-for-data-visualization-d3.js |
| Chrome inside Node.js | https://github.com/GoogleChrome/puppeteer |
| XLSX loader | https://github.com/mgcrea/node-xlsx |
| Node.js bindings for CNTK | https://github.com/nadavbar/node-cntk |
| API Repository | https://any-api.com/ |
| ORM | |
| Migração de . NET para JavaScript (Node.js) | https://www.reddit.com/r/webdev/comments/2val7s/as_a_net_developer_do_i_need_to_care_about_nodejs |
| Simplified JavaScript Jargon | http://jargon.js.org |
2022-12-07 11:42:19 -03:00
| RegExp | https://regexp101.com |
2019-03-01 15:34:29 -03:00
### Packages
2019-03-01 17:41:18 -03:00
| Título | Descrição | URL |
|--------|----------------------------------|------------------------------------|
| MSAL | Microsoft Authentication Library | https://www.npmjs.com/package/msal |
2019-03-01 15:34:29 -03:00
2020-06-11 09:48:42 -03:00
### Visual Studio Code Shotcut keys
2019-03-01 15:34:29 -03:00
2020-06-11 09:48:42 -03:00
| Key | Description |
|--------------------------|-------------------------------------------------------------------------------|
| F8 | Next error. |
2020-10-19 14:10:32 -03:00
| F12 | Go to symbol definition. |
2020-06-11 09:48:42 -03:00
| F5 | Run. |
| CTRL + . | Auto refactoring (Fix). |
| ALT + SHIFT + DOWN ARROW | Duplicate the line code. |
| CTRL + SHIFT + H | Replace all followed by CTRL + ALT + ENTER on replace text box. |
| CTRL + SHIFT + B | Compile inside VSCode, you can also open an external terminal and run tsc -w. |
| CTRL + G | Go to the specified line. |
| CTRL + SHIFT + G | Goes to Git. |
2020-10-16 11:58:46 -03:00
| CTRL + SHIFT+P | Opens the Command Palette |
| CTRL + ALT+UP/DOWN ARROW | Enter the Vertical Selection mode |
| ALT + UP/DOWN ARROW | Move lines |
2022-12-22 11:26:12 -03:00
### Node Packages
2019-03-01 15:34:29 -03:00
2022-12-22 11:26:12 -03:00
| Title | Description |
|----------------------------------------------|--------------------------------------------------------------------------------|
2022-12-22 11:29:55 -03:00
| @azure/arm-appservice | |
| @azure/arm-cognitiveservices | |
| @azure/arm-resources | |
| @azure/arm-search | |
| @azure/arm-sql | |
| @azure/arm-subscriptions | |
| @azure/cognitiveservices-computervision | |
| @azure/keyvault-keys | |
| @azure/ms-rest-js | |
| @azure/msal-node | |
| @azure/search-documents | |
| @google-cloud/pubsub | |
| @google-cloud/translate | |
| @hubspot/api-client | |
| @microsoft/microsoft-graph-client | |
| @nosferatu500/textract | |
| @semantic-release/changelog | |
| @semantic-release/exec | |
| @semantic-release/git | |
| @sendgrid/mail | |
| @types/node | |
| @types/validator | |
| adm-zip | |
| alasql | |
| any-shell-escape | |
| async-promises | |
| basic-auth | |
| billboard.js | |
| bluebird | |
| body-parser | |
| botbuilder | |
| botbuilder-adapter-facebook | |
| botbuilder-ai | |
| botbuilder-dialogs | |
| botframework-connector | |
| botlib | |
| c3-chart-maker | |
| chatgpt | |
| chrome-remote-interface | |
| cli-progress | |
| cli-spinner | |
| core-js | |
| data-forge | |
| date-diff | |
| docxtemplater | |
| dotenv-extended | |
| exceljs | |
| express | |
| express-remove-route | |
2022-12-22 11:30:27 -03:00
| ffmpeg-static | Converts multiple video/audio format, wrapper to [ffpmeg](https://ffmpeg.org/). |
2022-12-22 11:29:55 -03:00
| google-libphonenumber | |
| googleapis | |
| ibm-watson | |
| indent.js | |
| js-beautify | |
| keyv | |
| koa | |
| koa-body | |
| koa-router | |
| lodash | |
| luxon | |
| mammoth | |
| moment | |
| ms-rest-azure | |
| nexmo | |
| node-cron | |
| node-nlp | |
| node-tesseract-ocr | |
| npm | |
| open | |
| pdf-extraction | |
| pdfkit | |
| phone | |
| pizzip | |
| pptxtemplater | |
| pragmatismo-io-framework | |
| prism-media | |
| public-ip | |
| punycode | |
| puppeteer | |
| puppeteer-extra | |
| puppeteer-extra-plugin-stealth | |
| qrcode | |
| qrcode-terminal | |
| readline | |
| reflect-metadata | |
| rimraf | |
| safe-buffer | |
| scanf | |
| sequelize | |
| sequelize-cli | |
| sequelize-typescript | |
| simple-git | |
| speakingurl | |
| ssr-for-bots" | |
| strict-password-generator | |
| swagger-client | |
| tabulator-tables | |
| tedious | |
| textract | |
| twitter-api-v2 | |
| typescript | |
| typescript-rest-rpc | |
| url-join | |
| vbscript-to-typescript | |
| vhost | |
| vm2 | |
| vm2-process | |
| walk-promise | |
| washyourmouthoutwithsoap | |
| whatsapp-web.js | |
| winston | |
| winston-logs-display | |
| yarn | |
### Node Packages (Dev Dependencies)
| Title | Description |
|----------------------------------------------|--------------------------------------------------------------------------------|
| simple-commit-message | |
| @types/url-join | |
| ban-sensitive-files | |
| commitizen | |
| cz-conventional-changelog | |
| dependency-check | |
| git-issues | |
| license-checker | |
| ngrok | |
| prettier-standard | |
| semantic-release | |
| travis-deploy-once | |
| ts-node | |
| tslint | |
2022-12-22 11:26:12 -03:00
2020-06-11 09:48:42 -03:00
### Visual Studio Code Extensions
2019-03-01 15:34:29 -03:00
2019-03-01 17:41:18 -03:00
| Title | Description |
|----------------------------------------------|-----------------------------------------------------------------|
| mbinic.tgit-cmds | Set of commands for launching TortoiseGit dialogs |
2019-03-01 15:34:29 -03:00
| tomashubelbauer.vscode-markdown-table-format | Formats MarkDown tables so that all columns have the same width |
2019-03-01 17:41:18 -03:00
| esbenp.prettier-vscode | VS Code plugin for prettier/prettier (wraps at column 80) |
| mikestead.dotenv | .env support |
| abhinavk99.codewall | Description here |
| christian-kohler.npm-intellisense | Description here |
| csholmq.excel-to-markdown-table | Description here |
| davidanson.vscode-markdownlint | Description here |
| eg2.ts-tslint | Description here |
| eg2.vscode-npm-script | Description here |
| esbenp.prettier-vscode | Description here |
| formulahendry.auto-rename-tag- | Description here |
| gruntfuggly.align-mode | Description here |
| jmfirth.vsc-space-block-jumper | Description here |
| kaiwood.indentation-level-movement | Description here |
| mbinic.tgit-cmds | Description here |
| mechatroner.rainbow-csv | Description here |
| mikestead.dotenv | Description here |
| sirtori.indenticator | Description here |
| tandy.color-basic | Description here |
## Common tasks
| Task | Description |
|---------------|-------------------------------------|
| npm update -g | Updates NPM |
| node -v | Checks node version |
| ncu -a | Update all packages in package.json |
2020-11-12 08:47:38 -03:00
## Useful documentation
2023-11-08 09:03:21 -03:00
- https://www.typescriptlang.org/docs/handbook (TypeScript Documentation).
- https://www.domstamand.com/removing-user-consent-from-an-azure-ad-application/