generalbots/docs/src/chapter-06-gbdialog/keywords.md
Rodrigo Rodriguez (Pragmatismo) 06c75cb690 Looking at this diff, I can see it's a comprehensive documentation
update and code refactoring focused on:

1. Adding new documentation pages to the table of contents
2. Restructuring the bot templates documentation
3. Changing keyword syntax from underscore format to space format (e.g.,
   `SET_BOT_MEMORY` → `SET BOT MEMORY`)
4. Updating compiler and keyword registration to support the new
   space-based syntax
5. Adding new keyword modules (social media, lead scoring, templates,
   etc.)

Refactor BASIC keywords to use spaces instead of underscores

Change keyword syntax from underscore format (SET_BOT_MEMORY) to more
natural space-separated format (SET BOT MEMORY) throughout the codebase.

Key changes:
- Update Rhai custom syntax registration to use space tokens
- Simplify compiler preprocessing (fewer replacements needed)
- Update all template .bas files to use new syntax
- Expand documentation with consolidated examples and new sections
- Add new keyword modules: social_media, lead_scoring, send_template,
  core_functions, qrcode, sms, procedures, import_export, llm_macros,
  on_form_submit
2025-11-30 10:53:59 -03:00

11 KiB
Raw Blame History

Keyword Reference

This section lists every BASIC keyword implemented in the GeneralBots engine. Each keyword page includes:

  • Syntax Exact command format
  • Parameters Expected arguments
  • Description What the keyword does
  • Example A short snippet showing usage

The source code for each keyword lives in src/basic/keywords/. Only the keywords listed here exist in the system.


Complete Keyword List (Flat Reference)

Keyword Category Description
ADD MEMBER Communication Add member to a group
ADD SUGGESTION UI Add clickable suggestion button
ADD TOOL Tools Register a tool for the session
AGGREGATE Data Perform SUM, AVG, COUNT, MIN, MAX operations
BOOK Special Book an appointment
CLEAR HEADERS HTTP Clear all HTTP headers
CLEAR KB Knowledge Unload knowledge base from session
CLEAR SUGGESTIONS UI Remove all suggestion buttons
CLEAR TOOLS Tools Remove all registered tools
COMPRESS Files Create ZIP archive
COPY Files Copy a file
CREATE DRAFT Communication Create email draft
CREATE SITE Tools Generate a website
CREATE TASK Tools Create a task
DELETE Data Delete records from table
DELETE FILE Files Delete a file
DELETE HTTP HTTP Send HTTP DELETE request
DOWNLOAD Files Download file from URL
EXIT FOR Control Exit loop early
EXTRACT Files Extract ZIP archive
FILL Data Fill template with data
FILTER Data Filter records by condition
FIND Data Search in files or KB
FIRST Data Get first element
FOR EACH ... NEXT Control Loop through items
FORMAT Data Format strings and dates
GENERATE PDF Files Generate PDF from template
GET Variables Get variable or API data
GET BOT MEMORY Memory Retrieve bot-level persisted data
GRAPHQL HTTP Execute GraphQL query
GROUP BY Data Group data by field
HEAR Dialog Get input from user
IF ... THEN ... ELSE ... END IF Control Conditional logic
INSERT Data Insert new record
INSTR String Find position of substring
IS NUMERIC String Check if value is numeric
JOIN Data Join two datasets
LAST Data Get last element
LIST Files List directory contents
LLM AI Query language model
MAP Data Map field names
MERGE Data Merge data into table
MERGE PDF Files Merge multiple PDFs
MOVE Files Move or rename file
ON Events Event handler
PATCH HTTP Send HTTP PATCH request
PIVOT Data Create pivot table
POST HTTP Send HTTP POST request
PRINT Debug Debug output to console
PUT HTTP Send HTTP PUT request
READ Files Read file content
REMEMBER Memory Store user-specific memory
SAVE Data Save data to table (upsert)
SAVE FROM UNSTRUCTURED Data Extract structured data from text
SEND MAIL Communication Send email
SET Variables Set variable value
SET BOT MEMORY Memory Persist data at bot level
SET CONTEXT AI Add context for LLM
SET HEADER HTTP Set HTTP header
SET SCHEDULE Events Schedule script execution
SET USER Session Set user context
SOAP HTTP Execute SOAP API call
SWITCH ... CASE ... END SWITCH Control Switch statement
TALK Dialog Send message to user
UPDATE Data Update existing records
UPLOAD Files Upload file to storage
USE KB Knowledge Load knowledge base
USE TOOL Tools Register tool definition
USE WEBSITE Knowledge Associate website with session
WAIT Control Pause execution
WEATHER Special Get weather information
WEBHOOK Events Create webhook endpoint
WHILE ... WEND Control While loop
WRITE Files Write content to file

Keywords by Category

Core Dialog Keywords

Keyword Syntax Description
TALK TALK "message" Send message to user
HEAR HEAR variable or HEAR variable AS TYPE Get input from user
WAIT WAIT seconds Pause execution
PRINT PRINT "debug message" Debug output to console

Variable & Memory

Keyword Syntax Description
SET SET variable = value or let variable = value Set variable value
GET result = GET "path" Get variable or fetch data
SET BOT MEMORY SET BOT MEMORY "key", value Persist data at bot level
GET BOT MEMORY value = GET BOT MEMORY("key") Retrieve persisted data
REMEMBER REMEMBER "key", value Store user-specific memory

AI & Context

Keyword Syntax Description
LLM result = LLM "prompt" Query language model
SET CONTEXT SET CONTEXT "name" AS "value" Add context for LLM
SET USER SET USER userid Set user context

Knowledge Base

Keyword Syntax Description
USE KB USE KB "kbname" Load knowledge base
CLEAR KB CLEAR KB or CLEAR KB "kbname" Unload knowledge base
USE WEBSITE USE WEBSITE "url" Associate website with session
FIND result = FIND "file", "filter" Search in files or KB

Tools & Automation

Keyword Syntax Description
ADD TOOL ADD TOOL "toolname" Register tool for session
USE TOOL USE TOOL "toolname" Load tool definition
CLEAR TOOLS CLEAR TOOLS Remove all registered tools
CREATE TASK CREATE TASK "title", "description" Create a task
CREATE SITE CREATE SITE "alias", "template", "prompt" Generate a website
CREATE DRAFT CREATE DRAFT "to", "subject", "body" Create email draft

UI & Interaction

Keyword Syntax Description
ADD SUGGESTION ADD SUGGESTION "key" AS "display text" Add clickable button
CLEAR SUGGESTIONS CLEAR SUGGESTIONS Remove all buttons

Data Operations

Keyword Syntax Description
SAVE SAVE "table", var1, var2, var3 Save data (upsert)
INSERT result = INSERT "table", data Insert new record
UPDATE rows = UPDATE "table", "filter", data Update records
DELETE rows = DELETE "table", "filter" Delete records
MERGE result = MERGE "table", data, "key" Merge data into table
FILTER result = FILTER data, "condition" Filter records
AGGREGATE result = AGGREGATE "SUM", data, "field" Aggregate operations
JOIN result = JOIN left, right, "key" Join datasets
PIVOT result = PIVOT data, "row", "value" Create pivot table
GROUP BY result = GROUP BY data, "field" Group data
MAP result = MAP data, "old->new" Map field names
FILL result = FILL data, template Fill template
FIRST result = FIRST collection Get first element
LAST result = LAST collection Get last element
FORMAT result = FORMAT value AS "pattern" Format strings/dates

File Operations

Keyword Syntax Description
READ content = READ "path" Read file content
WRITE WRITE "path", content Write to file
DELETE FILE DELETE FILE "path" Delete a file
COPY COPY "source", "destination" Copy a file
MOVE MOVE "source", "destination" Move/rename file
LIST files = LIST "path/" List directory
UPLOAD url = UPLOAD file, "path" Upload file
DOWNLOAD path = DOWNLOAD "url", "local" Download file
COMPRESS archive = COMPRESS files, "name.zip" Create ZIP
EXTRACT files = EXTRACT "archive.zip", "dest/" Extract ZIP
GENERATE PDF result = GENERATE PDF "template", data, "output.pdf" Generate PDF
MERGE PDF result = MERGE PDF files, "merged.pdf" Merge PDFs

HTTP & API Operations

Keyword Syntax Description
POST result = POST "url", data HTTP POST request
PUT result = PUT "url", data HTTP PUT request
PATCH result = PATCH "url", data HTTP PATCH request
DELETE HTTP result = DELETE HTTP "url" HTTP DELETE request
SET HEADER SET HEADER "name", "value" Set HTTP header
CLEAR HEADERS CLEAR HEADERS Clear all headers
GRAPHQL result = GRAPHQL "url", "query", vars GraphQL query
SOAP result = SOAP "wsdl", "operation", params SOAP call

Flow Control

Keyword Syntax Description
IF...THEN...ELSE IF condition THEN ... ELSE ... END IF Conditional
FOR EACH...NEXT FOR EACH item IN collection ... NEXT item Loop
EXIT FOR EXIT FOR Exit loop early
WHILE...WEND WHILE condition ... WEND While loop
SWITCH...CASE SWITCH value CASE x ... END SWITCH Switch statement

Events & Scheduling

Keyword Syntax Description
ON ON "event" CALL handler Event handler
SET SCHEDULE SET SCHEDULE "cron" Schedule execution
WEBHOOK WEBHOOK "endpoint" Create webhook

Communication

Keyword Syntax Description
SEND MAIL SEND MAIL "to", "subject", "body" Send email
ADD MEMBER ADD MEMBER "email", "group" Add to group

Special Functions

Keyword Syntax Description
BOOK BOOK "appointment" Book appointment
WEATHER weather = WEATHER "location" Get weather
INSTR pos = INSTR(string, search) Find substring
IS NUMERIC result = IS NUMERIC(value) Check if numeric
SAVE FROM UNSTRUCTURED data = SAVE FROM UNSTRUCTURED text, schema Extract structured data

Syntax Rules

DO

' Variable names (no underscores in names)
let ticketnumber = "TKT001"
let useremail = "user@example.com"

' SAVE with field names = variable names
SAVE "table.csv", ticketnumber, useremail, status

' Keywords with spaces
SET BOT MEMORY "last_ticket", ticketnumber
SET CONTEXT "name" AS "description"
ADD SUGGESTION "key" AS "Display text"
CLEAR SUGGESTIONS
USE KB "myknowledge"
USE TOOL "mytool"

' GET BOT MEMORY as function
let lastticket = GET BOT MEMORY("last_ticket")

DON'T

' NO: Complex object operations
SET object.field = value  ' WRONG
SAVE "table", object.id, object  ' WRONG

' NO: IF for input validation (use HEAR AS TYPE instead)
IF value = "" THEN  ' OK for logic, but for input use:
HEAR value AS STRING  ' Better - validates input type

Notes

  • Keywords are case-insensitive (TALK = talk = Talk)
  • String parameters can use double quotes or single quotes
  • Comments start with REM or '
  • Line continuation uses underscore (_)
  • Objects are created with #{ key: value } syntax
  • Arrays use [item1, item2, ...] syntax