📃
NewBot
  • NewBot, what is it?
  • ConverseScript Syntax
    • Variables
    • Arithmetic
    • Boolean
    • Array and object
    • Entering text and output
    • Magic variables
    • Condition
    • Loop
    • Functions
    • The decorators
      • Use @Condition
      • Use @Action
      • Use @Format
      • Use @Intent
      • Use @Event
  • Prebuilt Formats for Widget
    • Quick Replies
    • Multi Cards
    • Articles
    • Form
  • Pre-built function for the widget
    • Request()
    • Map()
    • _ (lodash)
  • Get Started with Framework
    • Install
    • Main Skill
    • Write the conversational script
  • Use NewBot Framework JS
    • Create a skill (more details)
      • Relationship between skills
      • Use the functions of a child competency
      • Conditional
      • Control access to a skill
    • Create a JavaScript function and trigger it in ConverseScript
    • The constants
    • Write formats
      • Write and use multi-formats
      • Share formats
    • Internationalization (i18n)
    • Set up an NLP system
      • Share the NLP system
      • Use DialogFlow
    • Deploy on the browser
    • Run the chatbot on NodeJS
    • Send data when running the chatbot
    • The middlewares
    • Save the user's progress
    • User object
  • Unit Tests
    • Test a scenario
    • Test variables
    • Spy a function
    • Create a mock
    • Test the events
    • Test the actions
Powered by GitBook
On this page
  • Call in the main script
  • Property condition

Was this helpful?

  1. Use NewBot Framework JS
  2. Create a skill (more details)

Conditional

PreviousUse the functions of a child competencyNextControl access to a skill

Last updated 3 years ago

Was this helpful?

It happens several times that one wishes to execute a different skill according to the platform or certain information of the user. For example, we could have a following skill:

profile() {
    Messenger.getProfile() // custom function to get Messenger profile
    > Your name is { : response.data.name }
}

We can think that this method allows to recover the

However, we want to achieve a universal scenario and have the same :

profile() {
    Line.getProfile() // custom function to get Line profile
    > Your name is { : response.data.displayName }
}

We will need to use a conditional skill to switch from one to another depending on the platform:

import formats from "newbot-formats";
import code from "./main.converse";

import profileMessengerSkill from "./skills/profile/messenger/profile";
import profileLineSkill from "./skills/profile/line/profile";

export default {
  code,
  skills: {
    formats,
    profileSkill: [
      {
        skill: profileMessengerSkill,
        condition(data, user) {
          return data.session.platform == "messenger";
        }
      },
      {
        skill: profileLineSkill,
        condition(data, user) {
          return data.session.platform == "line";
        }
      }
    ]
  }
};

Note several points:

  1. The name of the skill is always the same profileSkill

  2. We use the condition property that returns a Boolean

Call in the main script

In the main script main.converse, we can call the skill using its name:

@Event('start')
start() {
    profileSkill.profile()
}

The right skill will be triggered according to the platform!

Property condition

Settings

</api-table>

Return value

Boolean or Promise

We can delay the conditional test with a promise.

condition(data, user) {
    return new Promise(resolve => {
        setTimeout(() => {
            resolve(data.session.platform == "line")
        }, 2000)
    })
}
user profile on Messenger
on Line