Messages

Sending text message to device address

Params:

device_address - {string} - Device address

text - {string} - Message text

JS module
CLI
RPC
WS
core.sendTextMessageToDevice('0PZT5VOY5AINZKW2SJ3Z7O4IDQNKPV364', 'Hello!')
biot-core sendTextMessageToDevice 0PZT5VOY5AINZKW2SJ3Z7O4IDQNKPV364 Hello!
client.request('sendTextMessageToDevice', ['0PZT5VOY5AINZKW2SJ3Z7O4IDQNKPV364', 'Hello!'], (err, data) => {
if(err)
throw err;
console.log(data);
});
let message_id = id++;
socket.send(JSON.stringify({
id: message_id,
name: 'sendTextMessageToDevice',
args: ['0PZT5VOY5AINZKW2SJ3Z7O4IDQNKPV364', 'Hello!']
}));

Sending tech message to device address

Params:

device_address - {string} - Device address

object - {object} - Message object

JS module
CLI
RPC
WS
core.sendTechMessageToDevice('0PZT5VOY5AINZKW2SJ3Z7O4IDQNKPV364', {test: 'Hello!'})
biot-core sendTechMessageToDevice 0PZT5VOY5AINZKW2SJ3Z7O4IDQNKPV364 "{\"test\":\"Hello!\"}"
client.request('sendTextMessageToDevice', ['0PZT5VOY5AINZKW2SJ3Z7O4IDQNKPV364', {test: 'Hello!'}], (err, data) => {
if(err)
throw err;
console.log(data);
});
socket.send(JSON.stringify({
id: id++,
name: 'sendTextMessageToDevice',
args: ['0PZT5VOY5AINZKW2SJ3Z7O4IDQNKPV364', {test: 'Hello!'}]
}));

How to use?

const eventBus = require('byteballcore/event_bus');
eventBus.on('text', (from_address, text) => {
let objMessage;
try {
objMessage = JSON.parse(text);
if (objMessage.id || objMessage.version) objMessage = null;
} catch (e) {
}
if (objMessage) {
// this is tech
} else {
// this is text
}
});

In the near future, "tech" will have a separate handler