btnexus-node-python.btHook module

Blackout Nexus hook. Base class for all hooks

class btHook.Hook(settingsPath=None, **kwargs)[source]

Bases: btNode.Node

Blackout Nexus hook. Base class for all hooks

Constructor for the hook. extracting all important infos from the connectHash (either given as parameter, via environment variable CONNECT_HASH or in the .btnexusrc(prioritized in this order))

getCaption(lang, key)[source]

Returns a phrase from the captions file. If a list of phrases is given in the captions file one is chosen randomly. If only a String is given it returns this.

Parameters
  • lang (String) – the requested language

  • key (String) – key for a specific phrase

getDefaultSettings()[source]

Returns the default settings for the hook from the settings.json file - these can be used for local debugging. In production hooks the settings will be transmitted in onMessage

load(key, callback=None)[source]

load a value to a specific key in the NexusData Api

Parameters
  • key (String) – the key to which the value should be saved

  • callback (function pointer) – callback to handle the api response

onMessage(originalTxt, intent, language, entities, slots, branchName, peer, settings)[source]

Overload for your custum hook! - it needs to trigger say

React on a message forwarded to the hook.

Parameters
  • originalTxt (String) – the original text

  • intent (String) – the classified intent

  • language (String) – the (classified) language

  • entities (List of (String)) – List of used entities

  • slots (List of (String)) – List of used slots

  • branchName (String) – Name of the Branch

  • peer (dict) – param to indentify message origin

put(key, value, callback=None)[source]

add a value to a specific key in the NexusData Api - the value must be a list otherwise it will be overwritten

Parameters
  • key (String) – the key to which the value should be saved

  • value (Object) – the object which should be saved

  • callback (function pointer) – callback to handle the api response

save(key, value, callback=None)[source]

save a value to a specific key in the NexusData Api

Parameters
  • key (String) – the key to which the value should be saved

  • value (Object) – the object which should be saved

  • callback (function pointer) – callback to handle the api response

say(peer, message)[source]

publishes the hooks response.

Parameters
  • message (dict) – the message dict with at least the field ‘answer’

  • peer (Object) – the peer object handed from onMessage

state()[source]

publish the state of the hook