ChatMessage Object Members in SuiteScript 2.1

The ChatMessage object in SuiteScript 2.1 allows interaction with chat messages, including author roles and text content.

·2 min read·View Oracle Docs

The ChatMessage object in SuiteScript 2.1 provides a method for creating and managing chat messages within scripts, facilitating interaction with chatbots and other messaging tools.

ChatMessage Object Members

The ChatMessage object includes several important members that define the structure and purpose of chat messages. Below are the key members you should be aware of:

MemberTypeReturn Type / Value TypeSupported Script TypesDescription
ChatMessage.rolePropertystringServer scriptsThe author (role) of the chat message.
ChatMessage.textPropertystringServer scriptsText of the chat message, either the prompt sent by the script or the response returned by the LLM.

Property Descriptions

  1. Role: This property indicates who authored the chat message. It's a string type and is utilized predominantly by server scripts.
  2. Text: This property contains the actual text of the chat message, which can either be user input or chat bot outputs. It is also a string type and is used in server scripts.

Error Handling

If you attempt to set a property that is read-only, you will encounter the following error:

  • Error Code: READ_ONLY
  • Thrown If: An attempt is made to set the property value of a read-only member.

Syntax Example

Here's a syntax example demonstrating how to create a new chat message using the ChatMessage object:

suitescript
// Adding a chat message to the history
chatHistory.push({
role: llm.ChatRole.CHATBOT,
text: chatBotMessage // this is a previously defined string
});

For a more comprehensive script example related to creating chat messages, you can refer to the N/llm Module Script Samples.

Who This Affects

This article is primarily directed towards:

  • Developers: Those implementing server scripts using the SuiteScript framework.
  • Administrators: Admins overseeing chat functionalities and integrations within their NetSuite instance.

Source: This article is based on Oracle's official NetSuite documentation.

Key Takeaways

  • The ChatMessage object facilitates chat message management in SuiteScript.
  • It includes properties like role and text, critical for message definition.
  • Be mindful of read-only properties to avoid errors during implementation.

Frequently Asked Questions (4)

What script types are supported for using the ChatMessage object in SuiteScript 2.1?
The ChatMessage object is supported by server scripts in SuiteScript 2.1.
How is the 'role' property of the ChatMessage object utilized?
The 'role' property indicates the author of the chat message and is predominantly used in server scripts with a value of type string.
Can the text property of a ChatMessage object include both user input and chatbot outputs?
Yes, the 'text' property of a ChatMessage object can contain the actual text of a chat message, which includes both user input and chatbot outputs, and it is used as a string in server scripts.
What error might occur if you attempt to modify a read-only property in a ChatMessage object?
If you attempt to set a value on a read-only property in a ChatMessage object, you will receive an error with the code 'READ_ONLY.'
Source: ChatMessage Object Members Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in General

View all General articles →