Snippet


Introduction
This document provides guidance on using JavaScript (NodeJS) snippets within the Floatbot platform. These snippets are versatile and can be utilized in different parts of the platform including Prompts, Workflows, and AgentM

Snippet lets you create JavaScript (NodeJS) APIs that you can use to push/pull data from backend, call third party APIs and more.
Goto variables >> snippet

  • Add snippet by giving name to your snippet
  • You can run, save or download your snippet.
  • Snippets can be used within workflows, prompt or agent, select from the dropdown as per your requirements.
  • You can run and test your snippets by mentioning test cases.

Snippet Locations

  • LLM Prompts
  • Workflow
  • AgentM

You can select the desired location for your snippet usage via a dropdown menu located at the top right of the interface.

Accessing Attributes with `params`

  • The `params` object is available for accessing passed attributes.
  • For example, `params.first_name` can be used to access the `first_name` variable.

Output of the Snippet

  • The output is determined by the value assigned to the `item` object within your snippet.
  • In AgentM: The `item` variable should be a string.
  • In Prompts and Workflow: The `item` variable should adhere to a specific schema.

Use Cases

  • The snippet can be used to display text, buttons, cards, and quick replies.
  • It can also return `null` for an empty response.
  • The `set_attributes` object within the snippet can be used to set user specific variables.

Schema of the `item` Object

The schema for the `item` object is detailed in the following TypeScript interfaces:

interface Item {
    set_attributes?: { [key: string]: string };
    data: DataItem[];
}

interface DataItem { code: string; text: string; nextAgentM?: boolean; attribute: string; as_dropdown: boolean | 0 | 1; quick_reply?: QuickReply[]; cards?: Card[]; buttons?: Button[]; image?: Image; }
interface QuickReply { title: string; key: string | number; icon_url?: string; redirect?: string; }
interface Card { image_url?: string; title?: string; subtitle?: string; item_url?: string; buttons?: Button[]; }
interface Button { title: string; target?: boolean; type?: string; visitor_counter?: number; redirect?: string; link?: string; attributes?: string; success_attributes?: string[]; currency?: string; price?: number; invoiceTable?: InvoiceTableItem[]; }
interface InvoiceTableItem { name?: string; price?: number; }

Below is a snapshot showing how to return quick replies from snippet

snap 1

Below is a snapshot showing how to return text item from snippet

snap 2

Once you have created your snippet, you need to select it from workflow/ prompt or agent M

snap 3

ON THIS PAGE