The Message object
Whenever you are handling user input in Bubblescript, you will work
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.
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 Google Assistant, Alexa and the like)
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.
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
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"].
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.
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,
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
The detected intent. When intents were defined using the Training tab
in Botsquad, 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
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
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
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
The structured data that was the result of submitting the alternative
input method. For instance, in the case of a form
message.data holds all form data. For regular (type =
message.data is always empty.
Automatic conversion to string¶
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.