I sincerely believe that the popularity of the platform is correlated with the ease with which it is used. This also applies to writing software products for BitShares. Thus, I set myself the goal of reducing the barrier for programmers to enter the world of BitShares. The first stage was the implementation of
btsdex.js
oriented primarily to traders. But the subscription to change the account realized there seemed to me rather convenient not only for trading, but also for notification via third-party services. For example, I implemented bts-notifier, which will tell if in your account there will be a transfer of funds, creating order or fill order. On the basis of it you can build a notifier for email, Slack and other similar services.
For my part, I will do everything in my power to make this bot work consistently and stably. But all this I draw attention to, that this bot is only an example of use not intended for industrial use.
How to check it out
To try it out in work, just find the bot in the telegraph @btsnotifierbot.
Add tracking account
and wait until something happens)
Implementation
Logic of the bot itself is divided into two files database.js
andmain.js
. Most likely it is already clear from the name that in database.js
is the logic of storing information about subscriptions. The main logic is in main.js
. The settings for the entire program are in config.js
.
After the startup, the program connects to the BitShares blockchain, sets up telegram notifications, and starts waiting for either messages from the telegram or changes in the BitShares account being tracked.
I used the packages:
btsdex
for working with blockchain,telegraf
for working with telegram,i18n
for multilanguage application.
btsdex
is used very simply:
const
BitShares = require ('btsdex'),
...
BitShares.init (config.node);
BitShares.subscribe ('connected', start); // after establishing the connection, call start
async function start () {
...
BitShares.subscribe ('account', funcs [acc], acc); // subscription to acc account
...
}
telegraf
is also quite easy to use:
async function start () {
...
bot = new Telegraf (config.telegram.token)
bot.start (greeting) // call the function greeting if the bot wrote `/ start`
bot.hears (I18n.match ('menu.add_account'), addWaitAcc) // if someone wanted to add an account to call addWaitAcc
bot.hears (I18n.match ('menu.remove_account'), removeWaitAcc)
bot.hears (I18n.match ('menu.show_accounts'), showAcc)
bot.hears (I18n.match ('menu.settings'), settings)
bot.action ('cancel_wait_sub', cancelSub)
bot.action (/ remove _. * /, removeSub)
bot.on ('text', getText) // call getText if nothing above matches
bot.startPolling () // get started
}
i18n
is also nothing complicated:
async function start () {
...
i18n = new I18n ({
directory: `$ {__ dirname} / locales`,
defaultLanguage: 'en'
})
bot.use (i18n.middleware ())
}
// further everywhere where there is i18n.t ('here-some-text') - this is the localization of 'here-some-text'
All source code is available under the MIT license for github. So, quietly fork-up, modify and create your amazing services in the BitShares community.
Until a new meeting!
Congratulations @scientistnik! You have received a personal award!
1 Year on Steemit
Click on the badge to view your Board of Honor.
Do not miss the last post from @steemitboard:
SteemitBoard World Cup Contest - Quarter Finals - Day 2
Participate in the SteemitBoard World Cup Contest!
Collect World Cup badges and win free SBD
Support the Gold Sponsors of the contest: @good-karma and @lukestokes