Using NaifJs, the main node program is in charge to convert each incoming message from the channel,
calling the dialog manager with request
API.
NaifJs accepts requests data payload can be:
-
flat text
/* @param {string} text RequestDataObject */
-
a javascript object data structure
/* @param {{text: string, speech: boolean, optionalAttr: ..., optionalAttr: ...}} RequestDataObject */
containing at least a
text
attribute,(denoting a user written utterance), aspeech
attribute, denoting that user spoken the utterance, and more arbitrary optional parameters.
Request examples:
-
Text (written input), where data payload is a string:
naif.request( sessionid, 'my name is Giorgio Robino' )
-
Text (written input), where data payload is an object:
naif.request( sessionid, { text: 'my name is Giorgio Robino' } )
-
Speech (the transcript from a speech-to-text engine):
naif.request( sessionid, { text: 'my name is Giorgio Robino', speech: true } )
-
Audio message (whitout speech):
naif.request( sessionid, { audio: 'input_audio.ogg', text: '', speech: false } )
-
Image (where text attribute is maybe the transcript from a speech-to-text engine):
naif.request( sessionid, { image: 'input_image.jpg', text: 'my name is Giorgio Robino', speech: true } )
-
Video message (where text attribute is maybe the transcript from a speech-to-text engine):
naif.request( sessionid, { video: 'input_video.mp4', text: 'my name is Giorgio Robino', speech: true } )
Notes:
-
The requestDataObject is passed as argument to each input state function. That allows the handler to manage any kind of request data, not just texts.
-
The example textOrSpeech show how to use the data object to differentiate a spoken or texted input
-
the function API
toText(RequestDataObject)
return the text attribute of the request.