4.1.1 • Published 4 years ago

btnexus-hook v4.1.1

Weekly downloads
3
License
GPL-2.0-or-later
Repository
github
Last release
4 years ago

btNexus hooks

Blackout logo

AuthorMarc Fiedler
AuthorAdrian Lubitz
Emaildev@blackout.ai
Latest stable library version2.3.0
Required btNexus versions>= 2.2.4926

License

CopyrightLicense
(c)2018 Blackout Technologies, BremenGPLv3

Hooks are custom scripts that can be integrated into any point within a dialog to access external or living data. Any information and data that is not part of the original A.I. training falls under the category living data that can be integrated in a flow of a dialog with the help of btNexus Hooks

Introduction

The btNexus by Blackout Technologies is a platform to create Digital Assistants and to connect them via the internet to multiple platforms. Those platforms can be websites, apps or even robots. The btNexus consists of two major parts, the first is a network that can connect multiple micro service and the second is a sophisticated UI, that enables the user to train A.I.-based Digital Assistants. Those Digital Assistants can be anything, support chatbots or even robot personalities. Every user has one or multiple btNexus Instances, which means, it's their workspace. One btNexus Instance can host multiple personalities.

Prerequisites

What you need to get started with Hook development

Getting started

set up workspace

After installing the btNexus Workbench extension into your Visual Studio Code IDE press Ctrl+Shift+P or F1 to show all commands. Type in btNexus to see all commands asociated with the btNexus Workbench. Choose NEW and following the instructions. You should end up with an example project.

You can find the btNexus Workbench here: VSC btNexus Workbench

--

Once you are set uo, you can now proceed to:

onMessage (mandatory)

This callback gets triggered whenever the btNexus forwards a message to the hook It needs to call the method say(peer, message) otherwise the Hook will not respond. In onMessage the following parameters are available:

onMessage(text, intent, language, entities, slots, branch, peer)
  • text String with the original user phrasing
  • intent String with the name of the classified intent
  • language String Language tag of the language that the end-user is currently speaking in
  • entities Array of Objects that contain the name and the Value of each extracted entity: {name: "EntityName", value: "EntityValue"}
  • slots Array of Strings that contain all extracted slots
  • branch String, name of dialog branch that triggered the Hook
  • peer Object: btNexus Peer, used for responding to messages

onInit (optional)

This function is called when the Hook was Initialized. After onInit, the Hook will connect to btNexus.

    onInit(){
        // use the time to initialize your own variables
    }

onReady (optional)

Is called when the connection to btNexus was authenticated successfully.

    onReady(){
        console.log("Hook ready");
    }

onError (optional)

Gets called when btNexus encounters an error

    @param error, String, contains the error message
    @param code, Integer that contains the error code
    onError(error, code){ 
        console.dir(error);
        console.log("Error: "+error+" code: "+code); 
    }

onDisconnected (optional)

Gets called when ever the Hook disconnects from the btNexus network

    onDisconnect(){ 
        console.log("Disconnected from btNexus"); 
        console.log("Trying to reconnect..."); 
        // it tries to reconnect every second 
        setTimeout(() => { 
                this.connectToBtNexus(); 
        }, 5000); 
    }

API

You can use the following functions to exploit the full potential of your hook.

say (mandatory)

    @param peer, Object, the peer object from the onMessage callback
    @param message, Object, contains the message, which should be send as response
    say(peer, message)

The message Object needs to have at least the field answer. To include hyperreferences you need to use the hyperReferences field. See hyperReferences for more infos.

save (optional)

This function saves a key value pair in the btNexus Data.

    @param key, String, the key in the btNexus Data
    @param value, Object, an Object which should be saved
    @param callback, function pointer, a callback which should be triggered on the response
    save(key, value, callback)

put (optional)

This function adds a value to an array of data for a specific key in the btNexus Data. If there is no value to the specific key or it is not an array it will be overwritten.

    @param key, String, the key in the btNexus Data
    @param value, Object, an Object which should be saved
    @param callback, function pointer, a callback which should be triggered on the response
    put(key, value, callback)

load

This function loads a value from the btNexus Data.

@param key, String, the key in the btNexus Data
@param callback, function pointer, a callback which should be triggered on the response
load(key, callback)

connectToBtNexus

This function can be used for reconnecting the hook.

    connectToBtNexus()

btNexus Tools

In the btNexus world, there are some specific standards you need to follow in order to leverage the maximum use of it's power. One of those are called hyperReferences. What that means is that you can utilise hyperReference objects to reference elements from outside of the scope of your hook. Links, Buttons, Carousels, MailTos and Dialog Buttons are part of the current array of possible object types for a hyperReference.

Another tool that you can utilize is platformActions. These objects are designed for the platform interface that you are using, your personality communicates with humans: The HMI (Human Machine Interface) if you will. platformActions are much more complex as they transport not only context information for the HMI but can also contain telemetry, geometry, or odometry data for more complex interfaces.

Hyper References

Create your own hyperReference when you need it.

    {
        answer: "The cake is a lie!",
        hyperReferences: [
            {
                type: "link", 
                blank: true, 
                target: 'http://www.vanschneider.com/wp-content/uploads/2017/01/cake_1200w.jpg', 
                caption: "Get the cake"
            }
        ]
    }

Platform Actions(to come)

btNexus Data

With the btNexus Data, key-value pairs can be saved in btNexus. This data is accessible over the lifetime of a hook.

Handling Languages

If you want to provide multilingual support to your Hook you can do that with the languageDict implementation that comes with the btnexus-hook library.

Each Hook has a member variable called captions. You can access it via this.captions. You can get a language specific phrasing with the []-operator of the captions object.

In order to have a working language dictionary, you need to create a file called captions.json in the root folder of your hook.

Example

    {
        "de-DE": {
            "greeting": [
                "Hi",
                "Hallo",
                "Moin"
            ],
            "whoAreYou": [
                "Wer bist du?",
                "Kennen wir uns?"
            ]
        },
        "en-US": {
            "greeting": [
                "Hi",
                "Hello",
                "Sup"
            ],
            "whoAreYou": [
                "Who are you?",
                "Do we know eachother?"
            ]
        }
    }

If the setup of the captions.json was done correctly, you will be able to access any caption with the []-operator passing the name of the language as a string.

Example Usage

this.captions[language].fallback; // in the above example will return:  "Sorry, I can't find anything." if the language from onMessage is English

Additional Information

Hooks are Node.Js packages and therefore need to fulfil the package requirements of the NPM standart. https://docs.npmjs.com/files/package.json

btNexus is a product of Blackout Technologies, all rights reserved (https://blackout.ai/)

4.1.1

4 years ago

4.1.0

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

2.3.0

4 years ago

2.2.11

4 years ago

2.2.10

4 years ago

2.2.9

5 years ago

2.2.8

5 years ago

2.2.7

5 years ago

2.2.5

5 years ago

2.2.4

5 years ago

2.2.3

5 years ago

2.2.2

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.9

5 years ago

2.1.8

5 years ago

2.1.7

5 years ago

2.1.6

5 years ago

2.1.5

5 years ago

2.1.4

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.9

5 years ago

2.0.8

5 years ago

0.6.8

5 years ago

2.0.7

5 years ago

2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago