2019-03-01 15:34:29 -03:00
# .gbdialog Reference
2020-10-02 09:23:38 -03:00

2019-03-01 15:34:29 -03:00
2022-08-02 23:56:59 -03:00
General Bots BASIC using HEAR and TALK keywords provides a easy to write bot language accessible to everyone and used as incomer for people willing to make their own bot.
2020-10-01 10:01:56 -03:00
2022-11-06 22:04:17 -03:00
It is like creating a conversation Node.js application just using BASIC. All code will run isolated on a Node VM:

2019-03-01 15:34:29 -03:00
## Using Conversational BASIC
2019-05-12 13:36:58 -03:00
The following file types are loaded from a .gbdialog package: `.vbs` , `.vb` , `.basic` and `.bas` .
2019-03-01 15:34:29 -03:00
## General Bots BASIC reference
2022-06-06 09:03:19 -03:00
| Instruction / Usage | Description | Example |
| ------------------------------------------------------------- | --------------------------------------------------------------------------- |----|
2022-06-06 09:08:54 -03:00
| HEAR _variable_ | Hears something from the person into a _variable_ for later use. | < pre > HEAR name < br /> TALK "Your name is " + name.< br /></ pre > |
2020-08-20 08:57:18 -03:00
| confirm _variable_ (Comming soon) | Waits for confirmation like 'yes', 'y', 'yeah' and return true or false |
2022-06-06 09:08:54 -03:00
| TALK _message_ | Talk the specified _message_ to the person. | < pre > TALK "Hello world." </ pre > |
2020-08-20 08:57:18 -03:00
| GENERATE A PASSWORD | Creates a new password into the system variable **password** for later use. |
| CREATE A BOT FARM USING _params_ | Deploys a new bot farm to the cloud. |
| WAIT _seconds_ | Wait a number of seconds before continuing the conversation. |
2021-05-18 13:59:29 -03:00
| _variable_ = GET "_file_.xlsx", "_A1:A1_" | Gets the value of the cell specified in range address |
| SET "_file_.xlsx", "_A1:A1_", 42 | Gets the value of the cell specified in range address |
| _variable_ = GET "https://server/query" | Gets the value of the cell specified in range address |
| POST "https://", _data_ | Gets the value of the cell specified in range address |
| wait _seconds_ | Wait a number of seconds before continuing the conversation. |
| HEAR _variable_ AS EMAIL | |
| HEAR _variable_ AS DATE | |
| HEAR _variable_ AS NAME | |
2022-01-08 11:45:01 -03:00
| HEAR _variable_ AS INTEGER | eg.: HEAR approve as Boolean. |
2021-05-18 13:59:29 -03:00
| HEAR _variable_ AS BOOLEAN | |
| HEAR _variable_ AS HOUR | |
| HEAR _variable_ AS MONEY | |
2021-05-18 14:07:15 -03:00
| HEAR _variable_ AS MOBILE | |
2022-06-04 10:58:09 -03:00
| * HEAR _variable_ AS FILE | Returns a file uploaded by user to be saved with SAVE _variable_ AS "folder/folder/file" on .gbdrive. |
2022-02-04 13:56:39 -03:00
| HEAR _variable_ AS AUDIO | Returns a audio uploaded by user to be saved with SAVE. |
2021-05-18 14:07:15 -03:00
| HEAR _variable_ AS ZIPCODE | |
| HEAR _variable_ AS "Abacate", "Maçã", "Morango" | Displays the specified menu and waits for this input until user select one of them. |
| HEAR _variable_ AS LANGUAGE | |
2021-09-17 15:54:04 -03:00
| HEAR _variable_ AS LOGIN (internal) | Waits for Active Directoy login integration before proceeding with the dialog . |
2021-11-19 16:43:59 -03:00
| GO TO [number,] dialogName | Transfers the conversation to a next dialog for the specificed number or as last command, transfers the context to this dialog. |
2021-11-19 17:18:49 -03:00
| SEE CAPTION OF _url_ AS _variable_ | Extracts an caption, using a pre-trained neural network, from a image. |
2021-11-19 17:17:08 -03:00
| SEE TEXT OF _url_ AS _variable_ | Extracts text from the image in a OCR (Optical Character Recognition) feature. |
2023-03-06 09:07:34 -03:00
| data = SELECT a, SUM(b) AS b FROM data GROUP BY a | Use SQL to manipulate a data variable returned from FIND or an array | _variable_ = CHART "pie", data| Generates a chart from data. |
| file = data AS IMAGE| Converts a two dimension array into an image file, ready to be used with SAVE AS or SEND FILE.|
| file = data AS PDF| Converts a two dimension array into an PDF file, ready to be used with SAVE AS or SEND FILE.|
| page = OPEN _url_ [AS #namedSession ] | Web automation retrival of a web page saving the session for reuse in other dialogs (optional).|
2022-06-04 11:07:40 -03:00
| * _variable_ = GET page, cssSelector, "body > img" | Retrives an element within an IFRAME specified by selector eg.: "[name=iFrameName]", to be used later. |
| * SET page, cssSelector, value | Define an field to value eg. "value 123" on the webpage specified by selector eg. "#id ". |
| * CLICK page, cssSelector | Clicks on an element inside the web page being automated by General Bots. |
2022-06-04 16:44:59 -03:00
| * file = DOWNLOAD _url_ | |
2022-08-02 23:53:07 -03:00
|NEW OBJECT| Creates a new object to be used with REST calls for example. < br > ```data = NEW OBJECT` `` <br> ` ``data.color = "blue"` `` |
|NEW ARRAY| Creates a new array. < br > ```data = NEW ARRAY` `` <br> ` ``data[0] = "blue"` `` |
2023-03-06 09:07:34 -03:00
| QRCODE | Creates a QRCode from specified text, eg.: file = QRCODE "data" |
2023-08-21 10:48:09 -03:00
| ADD NOTE | Adds a note to a file named Notes.xls of .gbdata. eg.: ADD NOTE "text" |
2023-08-23 11:26:39 -03:00
| ALLOW ROLE | Check if role specified in People sheet (.gbdata) will have access. eg.: ALLOW ROLE "DevOps" |
2023-10-04 17:30:59 -03:00
| CONTINUATION TOKEN| Retuns the value of the continuation token associated with the current dialog. |
2023-12-29 21:48:09 -03:00
| UPLOAD file | Uploads a file to a storage blob, like Azure Storage. |
| DIR path | Returns a list of files to be used with FOR EACH and performs actions. |
| TABLE name ON connection | Defines a TABLE on specified storage (database) connection. |
2022-06-04 11:17:01 -03:00
2023-10-02 16:13:28 -03:00
### Internal Variables and Functions.
These are variables that can be used in General Bots BASIC to faster dialog and services faster.
All values from .gbot Config.xlsx are also provided as variables, so it can be acessed directly in dialog.
| Instruction / Usage | Description |
| ------------------------------------------------------------- | ---------------------------------------------------------------------------- |
| aadToken() | Auto generated variable that contains Azure AD Token useful for calling Microsoft Web Services. |
2022-06-04 11:07:40 -03:00
### Options
2023-02-01 09:53:15 -03:00
| Instruction / Usage | Description |
| ------------------------------------------------------------- | ---------------------------------------------------------------------------- |
| SET PARAM name AS value | Defines a retrievable param in the storage in the scope of the user |
| GET PARAM name | Returns a previously user scoped param via SET PARAM from the storage. |
| SET HTTP HEADER _key = _value_ | Defines an HTTP header to be used to next GET call. |
| SET HTTP USERNAME = _value_ | Defines the HTTP username to be used to next GET call. |
| SET HTTP PASSWORD = _value_ | Defines the HTTP password to be used to next GET call. |
| * SET HEAR ON "mobile" | |
| SET MAX LINES _value_ | |
| SET SCHEDULE "2 * * * * *" | |
| SET LANGUAGE _value_ | |
| SET TRANSLATOR [ON or OFF] | |
| SET WHOLE WORD [TRUE or FALSE] | |
| SET THEME "dark" or "white" or "blue" | Defines the theme to the next content generation (PDF, images, vídeos, etc.) |
| SET OPERATOR [OR] | Defines OR operations on multiple FIND filters separated by comma, eg.: FIND "A1=2", "A3=4" |
2023-03-06 09:09:00 -03:00
| SET FILTER TYPE < comma separated list of types > | Uses the specified type in next FIND calls, disabling auto detection of filter type, eg.: SET FILTER TYPE date, string |
2022-06-04 10:18:25 -03:00
2023-10-02 16:13:28 -03:00
2022-06-04 10:58:09 -03:00
* = Work in progress.
2020-10-01 10:01:56 -03:00
2019-03-01 15:34:29 -03:00
## How To
2023-12-19 07:12:33 -03:00
### Use code in Excel
To reply as code in Excel, start the cell value with /basic followed by the code itself. Eg.:
```
/basic
TALK "Hello."
```
2021-12-20 11:28:35 -03:00
### Use General Bots computer vision
1. Develop a BASIC dialog and publish;

2. Test it in the conversation

2022-10-16 16:10:38 -03:00
### Using General Bots Web Automation to ask humans about unreadable captchas
2022-07-10 14:01:48 -03:00
2022-10-16 16:10:38 -03:00
```BASIC
2022-07-10 14:01:48 -03:00
mobile = "5521000000000"
page = GET HTML "https://www.any-website.com/"
SET page, "#usuario ", "user"
SET page, "#j_password ", "xxxxxxxxxxx"
img = GET page, "[name=iCaptcha]", "body > img"
SEND FILE TO mobile, img
TALK TO mobile, "Digite o código da imagem para prosseguir:"
SET HEAR ON mobile
HEAR captcha
SET page, "#captcha ", captcha
CLICK page, "#bt -login"
TALK TO mobile, "Login done, thanks."
```
2022-07-10 14:05:35 -03:00
### Using General Bots SQL and dynamic image and chart generation
On the fly table as images.
2022-10-16 16:10:38 -03:00
```BASIC
2022-07-10 14:05:35 -03:00
SET MAX LINES 1000
data = FIND "data.xlsx",
data = SELECT a, SUM(b) AS b FROM data GROUP BY a
SET THEME dark
png = data as IMAGE
SEND FILE png
```
On the fly charts
2022-10-16 16:10:38 -03:00
```BASIC
2022-07-10 14:05:35 -03:00
data = [10, 20, 30]
legends= "Steve;Yui;Carlos"
img = CHART "pie", data, legends
SEND FILE img
SAVE img as "folder/filename.jpg"
```
2022-07-10 14:10:36 -03:00
2022-11-11 10:47:12 -03:00
### Using General Bots Web Automation to custom notify about Google Calendar
2022-11-11 10:42:51 -03:00
```basic
REM Perform G. Login.
OPEN "https://accounts.google.com/ServiceLogin"
SET "#identifierId ", "test@gmail .com"
PRESS ENTER
WAIT 3
2022-11-11 10:47:12 -03:00
SET "input[type='password']", "******"
2022-11-11 10:42:51 -03:00
PRESS ENTER
WAIT 5
REM Enter on the Calendar page and capture the calendar grid inside the page.
OPEN "https://calendar.google.com/calendar/u/0/r?tab=mc& pli=1"
file = SCREENSHOT "div.K2fuAf"
REM Notify all team members with the updated calendar image.
list = FIND "People.xlsx", "Calendar=Y"
index = 1
DO WHILE index < ubound ( list )
row = list[index]
TALK TO row.Mobile, "Hello " + row.Name + ", here is your calendar:"
SEND FILE TO row.Mobile, file, "Calendar"
index = index + 1
LOOP
```
2022-07-10 14:11:37 -03:00
### Using complete General Bots Conversational Data Analytics
2022-07-10 14:10:36 -03:00
2022-10-16 16:10:38 -03:00
```BASIC
2022-07-10 14:11:37 -03:00
TALK "General Bots Labs presents FISCAL DATA SHOW BY BASIC"
TALK "Gift Contributions to Reduce the Public Debt API (https://fiscaldata.treasury.gov/datasets/gift-contributions-reduce-debt-held-by-public/gift-contributions-to-reduce-the-public-debt)"
2022-07-10 14:10:36 -03:00
result = GET "https://api.fiscaldata.treasury.gov/services/api/fiscal_service/v2/accounting/od/gift_contributions?page[size]=500"
data = result.data
data = SELECT YEAR(record_date) as Yr, SUM(CAST(contribution_amt AS NUMBER)) AS Amount FROM data GROUP BY YEAR(record_date)
TALK "Demonstration of Gift Contributions with AS IMAGE keyword"
SET THEME dark
png = data as IMAGE
SEND FILE png
DELAY 5
TALK " Demonstration of Gift Contributions CHART keyword"
img = CHART "bar", data
SEND FILE img
2022-07-10 14:11:37 -03:00
```
2022-07-10 14:10:36 -03:00

2022-07-10 14:07:35 -03:00
2022-07-10 14:05:35 -03:00
### Using General Bots Office templates
```
data = FIND "Customer.xlsx", "Idade=25"
doc = TEMPLATE "template.docx" WITH data
SAVE doc AS "resume.docx"
SEND EMAIL "noreply@pragmatismo .io", "Subject", doc
```
2021-12-20 11:28:35 -03:00
2022-10-16 16:10:38 -03:00
### Automating GitHub Issue creation with General Bots Automation
```BASIC
2022-10-16 16:11:58 -03:00
REM Realiza login no GitHub.
2022-10-16 16:10:38 -03:00
page = GET HTML "https://github.com/login"
SET page, "#login_field ", "username"
SET page, "#password ", "*******"
PRESS ENTER ON page
2022-10-16 16:11:58 -03:00
REM Verifica 2FA.
2022-10-16 16:10:38 -03:00
SET HEAR ON "5521999999999"
TALK "Digite o código de dupla autenticação enviado..."
HEAR code
SET page, "#otp ", code
PRESS ENTER ON page
REM Extrai cada Issue da planilha e cria no GitHub.
list = FIND "issues.xlsx"
index = 1
DO WHILE index < 38
2022-10-16 16:11:58 -03:00
row = list[index]
page = GET HTML "https://github.com/GeneralBots/BotServer/issues/new"
SET page, "#issue_title ", row.title
SET page, "#issue_body ", row.body
CLICK page, "#new_issue > div > div > div.Layout-main > div > div.timeline-comment.color-bg-default.hx_comment-box--tip > div > div.flex-items-center.flex-justify-end.d-none.d-md-flex.mx-2.mb-2.px-0 > button"
TALK "Issue '" + row.title + "' criado."
WAIT 5
index = index + 1
2022-10-16 16:10:38 -03:00
LOOP
EXIT
```
2022-11-11 10:42:51 -03:00
2020-08-20 08:57:18 -03:00
### Using POST data
You can use POST passing a variable as the second param in the POST call. The example
bellow shows how to call POST using an object that is returned from the Excel file.
Given the Excel file with the following contents and saved to the standard .gbdialog folder:
| tokenId | token | comment |
| ------- | ---------------- | ------- |
| 29187 | AAMkAGEzMWIxMmI5 | Prod1 |
| 98739 | jZWYtNGQ3My1iNmM | Prod2 |
The Word bellow will invoke POST call by using line contents as object attributes:
``` BASIC
obj = FIND "dados.xlsx", "tokenId=29187"
POST "https://server/query", obj
' obj here is {tokenId: 29187, token: "AAMkAGEzMWIxMmI5", comment: "Prod1"}
```
* OAuth2 is being implemented and no modification to previous calls will be necessary
as this configuration will be an administrative conversation to get the token setup.
2019-03-01 15:34:29 -03:00
### Generate a password for the person
```vb
talk "Let's generate a very dificult to guess password for the new bot:"
generate a password
talk "Your password is *" + password + "* . Keep it on a safe place only acessible to you."
```
### Get the list of cloud subscriptions
```vb
hear one of subscriptions with email, password into subscriptionId
talk "The subscription selected was: " + subscriptionId
```