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 | async 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. |
| simulateStreamMessage | async function | All Attributes | Simulates streaming a message into the chat. You can refer to the Simulated Stream example. |
| streamMessage | async function | All Attributes | Streams a message into the chat. You can refer to the Real-Time Stream example. |
| endStreamMessage | async function | All Attributes | Ends an existing message stream. You can refer to the Real-Time Stream example. |
| removeMessage | async function | All Attributes | Removes a message from the chat by message id. |
| setTextAreaValue | async function | All Attributes | Sets a value directly within the text area. |
| showToast | async function | All Attributes | Shows a toast that is dismissed after a duration or on user click. |
| dismissToast | async function | All Attributes | Dismisses a toast by toast id. |
| toggleChatWindow | async function | All Attributes | Opens or closes the chat component. |
| files | Array<File> | Only file Attribute | Represents the files uploaded by the user. |
If you are using functions from params, do remember that they are async and that without using await, behaviors 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): astringvalue 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): astringorJSX.Elementwhich is used as the content to send into the chat.sender(optional): astringvalue representing the sender of the message (userorbot). 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");
}
}
simulateStreamMessage
Description
Simulates streaming a message into the chat. This works by taking the entire text string and splitting it up to insert into the chat bubbble. For a detailed example on how to use this parameter, refer to the simulated stream example.
Type
async function
Parameters
content(required): astringvalue containing the text to simulate stream for.sender(optional): astringvalue representing the sender of the message (userorbot). Defaults tobot.simulateStreamChunker(optional): afunctioncontaining logic for chunking text content for streaming.
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"
await params.simulateStreamMessage(textToStream);
}
}
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): astringorJSX.Elementwhich is used as the content to send into the chat.sender(optional): astringvalue representing the sender of the message (userorbot). 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 < textToStream.length; i++) {
// this call replaces the last message sent by the bot with the new content
await params.streamMessage(textToStream.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): astringvalue representing the sender to end the stream for (userorbot). 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 < textToStream.length; i++) {
// this call replaces the last message sent by the bot with the new content
await params.streamMessage(textToStream.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): astringvalue 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
async function
Parameters
value(required): astringvalue to set inside the input text area.
Code Example
start: {
message: async (params) => {
await params.setTextAreaValue("This is the new input text area value!");
}
}
showToast
Description
Shows a toast that lasts for a duration (if specified).
Type
async function
Parameters
content(required): astringvalue representing the toast content to show.timeout(optional): anumbervalue representing the duration (in milliseconds) to show the toast for.
Code Example
start: {
message: async (params) => {
await params.showToast("Hello there, I last for 3 seconds!", 3000);
}
}
dismissToast
Description
Dismisses a toast with the given toast id.
Type
async function
Parameters
id(required): astringvalue representing the id of the toast to remove.
Code Example
start: {
message: async (params) => {
await params.dismissToast("fb8bf309-2a33-4683-955c-9e915768dadf");
}
}
toggleChatWindow
Description
Sets the chat window to be open or close.
Type
async function
Parameters
active(optional): abooleanindicating desired final state (if not specified, will simply toggle current state).
Code Example
start: {
message: async (params) => {
await params.toggleChatWindow(true);
}
}
files
Description
List of files uploaded by the user (only present in the file attribute).
Type
Array<File>
Parameters
- None
Code Example
start: {
file: (params) => {
console.log(params.files);
}
}