📃
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
  • Structure of your competence
  • With parameters
  • An asynchronous skill

Was this helpful?

  1. Use NewBot Framework JS

Create a skill (more details)

The interest of creating a skill is to modularize and structure your chatbot. We can also share the skill to the community

Structure of your competence

  • (my-skill)

    • my-skill.js

    • my-skill.converse

Let's create our scenario as usual in the JS file:

import code from './my-skill.converse'

export default {
    code
}

And in the ConverseScript

@Intent(/hello/i)
hey() {
    > Hey !
}

With parameters

If we want to send parameters, such as a token, the skill must return a function:

skills/my-skill.js

import code from './my-skill.converse'

export default function(token) {
    return {
        code
    }
}

In your main script:

import mySkill from './skills/my-skill'

export default {
    skills: {
        mySkill: mySkill('my-token')
    }
}

It is possible to write it this way too:

import mySkill from './skills/my-skill'

export default {
    skills: {
        mySkill: {
            skill: mySkill,
            params: ['my-token']
        }
    }
}

This time, the value of mySkill is an object with two properties:

  • skill: the path to competence

  • params: the parameters to send to the function of the competency

An asynchronous skill

The skill can return a promise

skills/my-skill.js

import code from './my-skill.converse'

export default function() {
    return new Promise((resolve) => {
        setTimeout(() => {
            resolve({
                code
            })
        }, 2000)
    })
}

So let's send the skill to the resolve() function of the promise. In the main script:

import mySkill from './skills/my-skill'

export default {
    skills: {
        mySkill
    }
}
PreviousWrite the conversational scriptNextRelationship between skills

Last updated 3 years ago

Was this helpful?