Params
This page documents all the parameters that may be used in an Attribute. Parameters provide you with contextual detail or utility functions to base your decisions on and interact with the chatbot.
Overview
The following table provides details about the parameters available for attributes. These parameters are accessible in all attributes, allowing dynamic behavior within your chatbot flows.
Name | Type | Availability | Description |
---|---|---|---|
userInput | string | All Attributes | Represents the user's input in the chat. |
currPath | string | All Attributes | Represents the current path in the chat (can be null if conversation flow has not started). |
prevPath | string | All Attributes | Represents the previous path in the chat (can be null if no previous path exists). |
goToPath | function | All Attributes | A utility function for navigating to another block. |
injectMessage | async function | All Attributes | A utility function to inject a message into the chat. |
streamMessage | async function | All Attributes | Streams a message into the chat. You can refer to the Real-Time Streaming example. |
endStreamMessage | async function | All Attributes | Ends an existing message stream. You can refer to the Real-Time Streaming example. |
removeMessage | async function | All Attributes | Removes a message from the chat by message id. |
setTextAreaValue | function | All Attributes | Sets a value directly within the text area. |
showToast | function | All Attributes | Shows a toast that is dismissed after a duration or on user click. |
dismissToast | function | All Attributes | Dismisses a toast by toast id. |
openChat | function | All Attributes | Opens or closes the chat component. |
files | FileList | Only file Attribute | Represents the files uploaded by the user. |
If you are using params.injectMessage
, params.streamMessage
, params.endStreamMessage
or params.removeMessage
, do remember that they are async
and that without using await
, behavior may be unexpected (e.g. multiple messages sent at once). This is a common pitfall!
Do consider checking out the live examples if you need more clarity on the usages of params
.
Param Details
Below is a detailed description on the usage of each parameter that may be used in an attribute.
userInput
Description
The last text area input submitted by the user.
Type
string
Code Example
start: {
message: (params) => `This is what the user last said: ${params.userInput}!`
}
currPath
Description
The current path the user is in, can be null
if the conversation flow has not started.
Type
string
| null
Code Example
start: {
message: (params) => `This is the user's current path: ${params.currPath}!`
}
prevPath
Description
The previous path the user came from, can be null
if no previous path (e.g. start
block).
Type
string
| null
Code Example
start: {
message: (params) => `This is the user's previous path: ${params.prevPath}!`
}
goToPath
Description
Sends the user to the specified path.
Type
function
Parameters
pathToGo
(required): astring
value representing the path to send the user to.
Code Example
start: {
message: (params) => {
// some logic here
params.goToPath("mystery_path");
}
}
injectMessage
Description
Sends a message into the chat.
Type
async function
Parameters
content
(required): astring
orJSX.Element
which is used as the content to send into the chat.sender
(optional): astring
value representing the sender of the message (user
orbot
). Defaults tobot
.
Code Example
start: {
message: (params) => {
await params.injectMessage("Good morning from the bot!");
await params.injectMessage(<div>Saying hi for the user!</div>, "user");
}
}
streamMessage
Description
Streams a message into the chat. This works by replacing the last sent message from the sender
with the content
specified. For a detailed example on how to use this parameter, refer to the real-time stream example.
Type
async function
Parameters
content
(required): astring
orJSX.Element
which is used as the content to send into the chat.sender
(optional): astring
value representing the sender of the message (user
orbot
). Defaults tobot
.
Code Example
start: {
message: (params) => {
// take for example the text below is streamed in character by character
const textToStream = "I'm just an example text"
for (let i = 0; i < text.length; i++) {
// this call replaces the last message sent by the bot with the new content
await params.streamMessage(text.slice(0, i + 1));
}
// to end the stream once we're done streaming
await params.endStreamMessage();
}
}
endStreamMessage
Description
Ends the streaming of message into the chat - users should call this when done with params.streamMessage
. Note that not calling params.endStreamMessage
may cause chat history and the emitting of events to function incorrectly.
Type
async function
Parameters
sender
(optional): astring
value representing the sender to end the stream for (user
orbot
). Defaults tobot
.
Code Example
start: {
message: (params) => {
// take for example the text below is streamed in character by character
const textToStream = "I'm just an example text"
for (let i = 0; i < text.length; i++) {
// this call replaces the last message sent by the bot with the new content
await params.streamMessage(text.slice(0, i + 1));
}
// to end the stream once we're done streaming
await params.endStreamMessage();
}
}
removeMessage
Description
Removes a message from chat with the given message id.
Type
async function
Parameters
id
(required): astring
value representing the id of the message to remove.
Code Example
start: {
message: (params) => {
await params.removeMessage("2e032ac4-b2bf-49e9-8897-706ad4dd214d");
}
}
setTextAreaValue
Description
Sets a value inside the input text area.
Type
function
Parameters
value
(required): astring
value to set inside the input text area.
Code Example
start: {
message: (params) => {
params.setTextAreaValue("This is the new input text area value!");
}
}
showToast
Description
Shows a toast that lasts for a duration (if specified).
Type
function
Parameters
content
(required): astring
value representing the toast content to show.timeout
(optional): anumber
value representing the duration (in milliseconds) to show the toast for.
Code Example
start: {
message: (params) => {
params.showToast("Hello there, I last for 3 seconds!", 3000);
}
}
dismissToast
Description
Dismisses a toast with the given toast id.
Type
function
Parameters
id
(required): astring
value representing the id of the toast to remove.
Code Example
start: {
message: (params) => {
params.dismissToast("fb8bf309-2a33-4683-955c-9e915768dadf");
}
}
openChat
Description
Sets the chat window to be open or close.
Type
function
Parameters
isOpen
(required): aboolean
indicating if chat window should be set open.
Code Example
start: {
message: (params) => {
params.openChat(true);
}
}
files
Description
List of files uploaded by the user (only present in the file attribute).
Type
FileList
Parameters
- None
Code Example
start: {
message: (params) => {
params.openChat(true);
}
}