How to build an echo bot for Byteball Platform

in #utopian-io6 years ago (edited)

Repository

https://github.com/byteball/byteballcore

What Will I Learn?

Hello everyone. Today we're going to develop a simple Echo Bot for the Byteball Platform.

  • You will learn how to receive messages
  • You will learn how to send messages

Requirements

  • Node.js installed
  • A Wallet with Tingos.

Difficulty

Basic

Tutorial Contents

Set up

Let's first create our package.json file. You can do it either running npm init or manually.

{
    "name": "test-echo-bot",
    "version": "1.0.0",
    "description": "Testing bot",
    "main": "echo.js",
    "author": "gustavoaca1997",
    "license": "MIT",
    "dependencies": {
        "byteballcore": "git+https://github.com/byteball/byteballcore.git",
        "headless-byteball": "git+https://github.com/byteball/headless-byteball.git"
    }
}

I'm gonna explain the dependencies:

  • byteballcore: This is a library used in Byteball clients.
  • headless-byteball: This is a headless alternative of the GUI wallet for Byteball network. It is designed for an always-online deployment on a server.

Now we're going to create the configuration file, called conf.js.

exports.deviceName = 'Echo bot';
exports.permanent_pairing_secret = '0000';
exports.hub = 'byteball.org/bb';
exports.bLight = true;
  • Device name is an user friendly name of your device.
  • The Pairing Secret is going to be part of your pairing code.
  • The hub is set to default hub, operated by @tonych.
Build bot

Let's create a file called echo.js. Inside of it, require the libraries needed:

const eventBus = require('byteballcore/event_bus.js');
const headlessWallet = require('headless-byteball');
const conf = require('byteballcore/conf.js');

Now all we gotta do is listen to text messages:

eventBus.on('text', function(from_address, text) {
    // listen to messages
});

To send a message to the device that sent us the last message, we are gonna use sendMessageToDevice() from byteballcore/device.js

eventBus.on('text', function(from_address, text) {
    
    var device = require('byteballcore/device.js');
    device.sendMessageToDevice(from_address, 'text', text);

});
Bring bot to life

Now we need to install it dependencies with npm install and run it with node echo.js. We need to type a passphrase and it's all. You will se printed bot's pairing code (the code you will use to start chatting with it).

Proof of Work Done

https://github.com/gustavoaca1997/byteball-echo-bot

Sort:  

Thank you for your contribution.
Your tutorial content is already extensively covered in the documentation and possibly elsewhere on the web, and hence does not add much value.
If you wish to write tutorials for this particular project, try to tackle less-documented concepts and in more detailed and thorough manner.

Your contribution has been evaluated according to Utopian policies and guidelines.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thanks for the feedback.

Do you need a headless wallet installed to host the bot?

Coin Marketplace

STEEM 0.29
TRX 0.12
JST 0.033
BTC 63318.34
ETH 3108.17
USDT 1.00
SBD 3.97