Skip to content

The Message object

Whenever you are handling user input in Bubblescript, you will work with the message and `answer variables. These variables have a special contents, namely a struct. The Message struct holds the text that the user typed (or spoke), and besides the raw text, it holds the result of the "NLP analysis" of this text.

The message struct contents

The message struct holds several fields which can be of interest.

message.text

The text of the user utterance. This text was either typed by the user, was a result of clicking a button or it was converted from speech using a Speech-to-Text mechanism (e.g. in the case of Telephony, Alexa and the like)

message.input_type

An indicator on how the message was constructed. Holds one of the following:

  • "keyboard" - when the message was entered on a keyboard.
  • "voice" - when the message was spoken.
  • "touch" - when the message the result of clicking a button or quick reply.

message.locale

The locale that was in effect in the conversation at the time this message was sent to the bot. This is not the detected locale; which is set in message.stats.detected_language.

message.sents

The text of the message, split up in a list of its sentences, as string values. It can be the case that the user enters more than one sentence as a message. For example: "How are you? My name is Nick". In that case, message.sents will contain the following list: ["How are you?", "My name is Nick"].

message.stats

Various statistics derived from the message:

  • message.stats.word_count - The number of words in the message.

  • message.stats.token_count - The number of tokens (words + punctuation) in the message.

  • message.stats.detected_language - The result of running language detection on the message. This is implemented using the langdetect library.

message.captures

A map which contains the BML captures that were done while processing this message, if any.

There is also a shortcut for accessing the captures of a message, using the message.<capture> syntax:

dialog main do
  ask "How do you feel?", expecting: entity(match: "I feel _ %ADJ[=mood]")
  say answer.captures.mood
  say answer.mood
end

In this example we capture the first adjective that comes after the user says "I feel ..."; and store that in the mood capture, which then can be accessed either using message.captures.mood or the shorter message.mood.

message.intent

The detected intent. When intents were defined using the Training tab in DialoX, or when this bot has been connected to Dialogflow, intent resolution will be run after each user utterance. When an intent is detected for the utterance, the message.intent field is filled using this intent.

The intent holds the following fields:

  • message.intent.id - The identifier of the intent

  • message.intent.label - Its label

  • message.intent.confidence - The confidence level*

  • message.intent.entities - Any entities that were captured as part of the intent*

  • Only for Dialogflow intent resolution

message.return

In the case of an entity capture, this contains the specified return value of the entity.

@yes entity(match: "yes|yep|sure", label: "Yes", return: "yes")

dialog main do
  ask "Are you sure?", expecting: [@yes]
  if answer.return == "yes" do
    say "You said yes."
  end
end

message.type

An indication of what kind of message it is. In most cases, and for most channels, this is the value "text". Only in the case when an alternative input method was used, the value will be set to the actual input method (e.g. item_picker). When the user cancels an input method, the value will be set to cancel.

message.data

The structured data that was the result of submitting the alternative input method. For instance, in the case of a form control, message.data holds all form data. For regular (type = text) messages, message.data is always empty.

Automatic conversion to string

Whenever a message is used in a function or in a context that expects a string, for instance, as a part of a say statement, it is automatically converted into a string:

dialog main do
  ask "Tell me something:"
  say "You said: " + answer
end

Under water, the string conversion takes the .text field of the message to use as the string representation.