Skip to main content

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.

NameTypeAvailabilityDescription
userInputstringAll AttributesRepresents the user's input in the chat.
currPathstringAll AttributesRepresents the current path in the chat (can be null if conversation flow has not started).
prevPathstringAll AttributesRepresents the previous path in the chat (can be null if no previous path exists).
goToPathfunctionAll AttributesA utility function for navigating to another block.
injectMessageasync functionAll AttributesA utility function to inject a message into the chat.
streamMessageasync functionAll AttributesStreams a message into the chat. You can refer to the Real-Time Streaming example.
endStreamMessageasync functionAll AttributesEnds an existing message stream. You can refer to the Real-Time Streaming example.
removeMessageasync functionAll AttributesRemoves a message from the chat by message id.
setTextAreaValuefunctionAll AttributesSets a value directly within the text area.
showToastfunctionAll AttributesShows a toast that is dismissed after a duration or on user click.
dismissToastfunctionAll AttributesDismisses a toast by toast id.
openChatfunctionAll AttributesOpens or closes the chat component.
filesFileListOnly file AttributeRepresents the files uploaded by the user.
Caution

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!

Tip

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): a string 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): a string or JSX.Element which is used as the content to send into the chat.
  • sender (optional): a string value representing the sender of the message (user or bot). Defaults to bot.

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): a string or JSX.Element which is used as the content to send into the chat.
  • sender (optional): a string value representing the sender of the message (user or bot). Defaults to bot.

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): a string value representing the sender to end the stream for (user or bot). Defaults to bot.

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): a string 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): a string 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): a string value representing the toast content to show.
  • timeout (optional): a number 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): a string 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): a boolean 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);
}
}