Mind Expression Docs
English
  • Mind Expression Docs
  • Why Mind Expression
  • Quickstarts
    • Create Scope
    • Add Subject
    • Test
    • Audit
  • Concepts
    • Scopes
    • Subjects
    • Components
    • Sandbox
    • Conversation history
    • Webhooks and escalation
    • Knowledge
    • Live Chat
    • Target Messages
    • Analytics
  • How-to Guides
    • Set up webhooks and escalation
    • Manage global keys
    • Customize messages
    • Educate AI
      • Manage ontologies
      • Recognition Check
      • Semantic Relations
      • Manage entities
    • Steps
    • Components
      • Normal Components
        • Conditions
        • Selection Classes
        • Parameter Bundles
      • Response Components
        • Component Actions
    • Build Q&A Subjects
      • Case 1. Online Payment
      • Case 2. Data Plans
    • Build Info Search Subjects
      • Case 1. Data Usage
      • Case 2. Payment History
    • Build Query Freestyle Subjects
      • Case 1. Data Purchase
      • Case 2. Change Mobile Plan
    • Intelligent Process
      • Introduction to Mindscript
      • Mindscript with Mind Expression
      • Frequently Asked Question
      • Package: Collections and Sequenceable
      • Package: Collections Unordered
      • Package: Collections-Strings
      • Package: Engine-Conversation
      • Package: Kernel-HTTP
      • Package: Kernel-Methods
      • Package: Kernel-Numbers
      • Package: Kernel-Dates
      • Package: Kernel-Objects
      • Package: Kernel Exceptions
      • Package: Cryptography
    • Test and debug
    • Integration
      • Mind Expression API
      • Chat Widget
      • LINE
      • Facebook Messenger
      • Viber
      • Instagram
      • Discord
      • WhatsApp
      • Google Sheet
        • Google Sheet Webhook
      • Google Calendar
        • Google Calendar Webhook
        • Google Calendar: Use Cases
    • Audit AI Activities
    • Live Chat
    • Target Messages
    • Back up, import and restore Scopes
  • Reference
    • Glossary
    • API Docs
Powered by GitBook
On this page
  • Frequently Asked Question
  • Troubleshooting Guide

Was this helpful?

  1. How-to Guides
  2. Intelligent Process

Frequently Asked Question

Frequently Asked Question

How to include ' in a string

  • Double ' means one '.

"a Mindscript string: There's a problem."
'There''s a problem.'

How to include " in a comment

  • !" means one ".

"This is a comment, !" still in a same comment block."

How to repeat executing a block

"Print 1 2 3 4 5"
1 to: 5 do: [:i | Console print: i, ' '].

"Print 0 2 4 6"
0 to: 6 by: 2 do: [:i | Console print: i, ' '].

i := 1.
[ i <= 10 ] whileTrue: [ Console print: i, '. '.
  i := i + 1 ].

i := 1.
[ i > 10 ] whileFalse: [ Console print: i, '. '.
  i := i + 1 ].

How to check whether a variable is defined

We can use the message isDefined, which is available for all objects.

b := 10.
"As a is not defined before, the following code block will not be evaluated."
a isDefined ifTrue: [ b := b + 1].
"b is still 10 as a is undefined."
a := 1.
"After a is defined."
a isDefined ifTrue: [ b := b + 1].
"Now b is 11."

This feature is extremely useful when establishing rules for a specific subject.

When a variable is defined within a subject, it can be used in another subject within the same conversation, assuming it was defined earlier.

This demonstrates that variables can be accessed at the conversation level.

NOTE

If we declare a variable within a code block, its scope is limited to that specific block, rendering it invisible to other parts of the code. Conversely, A variable established outside the scope of any specific block of code can be accessed by other rules within the conversation, even if those rules pertain to distinct subjects.

For example, if a Mindscript rule has the following code:

a := {  }.
a ifNil: [ 
  b := 10.
  a := b ].

The variable a is accessible to other rules within the scope, whereas the visibility of the variable b is confined solely to the local code block in which it resides.

How to define a local function

In Mindscript, a local function is synonymous with a code block. This block can be executed by sending it the message value, value:, or value:value:.

For example:

aBlock := [ 1 ].
"Call this block by method `value`"
aBlock value = 1.

aBlock := [ :x | x + 1 ].
"Call this block by method `value:`"
(aBlock value: 3) = 4.

aBlock := [ :x :y | x + y + 1 ].
"Call this block by method `value:value:`"
(aBlock value: 3 value: 2) = 6.

How to insert a dynamically generated JSON string into the request body for a webhook

{
"json": {{$ jsonObject asJson}} 
} 

Troubleshooting Guide

Resolving 'No Implementation for obj: x and behavior-name y' Error

Also, if x is NIL, we need to ensure it's been assigned an accurate value.

Handling "junk in string" error in Mindscript

Problem: The need is to convert a parameter 'x' to an integer in Mindscript. However, the following code throws an error: 'junk in string "x"'.

num := Parameter at: 'x' asInteger.

Answer: In Mindscript, a unary message assumes priority over a keyword message. The execution of the given code, when the explicit parentheses are added, can be illustrated as follows:

num := Parameter at: ('x' asInteger).

To make the keyword message work as intended, parentheses are used for grouping. This refactors the code as follows:

num := (Parameter at: 'x') asInteger.

Hence, using parentheses to group your code elements correctly is critical for ensuring that the code executes as you intend. Understanding and using operator precedence is key in coding, especially in Mindscript where message precedence can alter the functionality of the code.

PreviousMindscript with Mind ExpressionNextPackage: Collections and Sequenceable

Last updated 1 year ago

Was this helpful?

Consider a scenario where you possess a JSON object stored in a MindScript variable named jsonObject, and your aim is to embed this JSON object into the body of a webhook request. To accomplish this, you can leverage the method from MindScript, seamlessly incorporating it into a mustache template as follows:

We should examine the , especially the sections labeled Package, to determine the appropriate Mindscript classes and behaviors.

asJson
Mind Expression Doc