0.0.14 • Published 6 years ago
minarai-client-sdk-js-websocket v0.0.14
minarai client SDK (for JavaScript/WebSocket)
Description
A SDK that enables you to connect minarai easily on Node.js, browser both.
Requirement
Install
on your project root
npm install -S Nextremer/minarai-client-sdk-js-websocket
or
yarn add https://github.com/Nextremer/minarai-client-sdk-js-websocket.git
Usage
import MinaraiClient from 'minarai-client-sdk-js-websocket';
const minaraiClient = new MinaraiClient({
ws: WebSocket,
lang: 'ja-JP',
websocketRootURL: 'ws://localhost:3000/ws', /* minarai WebSocket Connector URL */
websocketOptions: [], /* options for WebSocket https://developer.mozilla.org/ja/docs/Web/API/WebSocket */
applicationId: this.state.connectionInfo.applicationId, /* application's id you want to connect */
clientId: this.state.connectionInfo.clientId,
userId: this.state.connectionInfo.userId,
deviceId: this.state.connectionInfo.deviceId,
});
minaraiClient.init();
// binding events
minaraiClient.on('connect', function(){
console.log("## websocket connected. trying to join as minarai client");
});
minaraiClient.on('joined', function(){
console.log("## minarai CONNECTED");
});
minaraiClient.on( "message", function( data ){
console.log("recieve message");
console.log(data)
});
minaraiClient.on( "error", function( err ){
console.log("minarai client error");
console.log(err);
});
// send message "hello" to dialogue-hub every 3 seconds
setInterval( function(){
minaraiClient.send("hello");
}, 3000 );
references
constructor options
- ws: WebSocket Object
- lang: language option( default: "ja-JP" )
- websocketRootURL: root url of minarai WebSocket Connector
- websocketOptions: options for io.connect method (ex) {}
- applicationId: application id to connect
- clientId: clientId
- userId: userId
- deviceId: deviceId
- debug : set true to show debug logs
- slient : set true value to hide all the logs
methods
- send: send message to minarai
- arguments
- uttr: string: message to send
- options :
- lang: string: language option. ex: 'ja-JP'
- extra: any: you can pass extra info to minarai.
- arguments
- sendSystemCommand: send system command to minarai
- arguments
- command: string
- payload: any
- arguments
cli.send('hello', { lang: 'ja-JP', extra: {} });
cli.sendSystemCommand('happyEmotionDetected', { value: true });
events
- connect: when connected to minarai successfully
- joined: when signed in to minarai as client successfully
- disconnected: when disconnected to minarai successfully
- sync: when you or your group send message to minarai(for sync message between multiple devices)
- sync-system-command: when you or your group send system command to minarai(for sync system command between multiple devices)
- message: when minarai send any event