📃
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

Was this helpful?

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

Use the functions of a child competency

Let's use the skill of the previous chapter. We add a custom function.

skills/my-skill/my-skill.js

import code from 'my-skill.converse'

export default {
    code,
    functions: {
        hello() {
            return 'Hey'
        }
    }
}

But we can use it in the parent scenario.

main.js

import code from './main.converse'
import mySkill from 'skills/my-skill/my-skill'

export default {
    code,
    skills: {
        mySkill
    }
}

In main.converse, we will then have:

@Event('start')
start() {
    > { mySkill.hello() }
}

As we can see, we use the mySkill object to access functions.

Read directly a function of the conversational script

Without going through the functions property, we can directly read a function from the conversational script of the child skill. Using the code above, we add these instructions to the script:

skills/my-skill/my-skill.converse

askName() {
    > What's your name ?
    Prompt()
    return :text
}

main.converse

@Event('start')
start() {
    name = mySkill.askName()
    > Your name is { name }
}
PreviousRelationship between skillsNextConditional

Last updated 3 years ago

Was this helpful?