Steem Bots - Mention Notificator

in #utopian-io5 years ago

image.png


Repository:

https://github.com/steemit/steem-js

What Will I Learn?

  • You will learn how to see new transactions that go through the blockchain in real-time

Requirements

  • Node.JS
  • SteemJS

Difficulty

  • Basic

Curriculum

The Tutorial

Hello guys, today I will teach you how to make a mention notifier!
first, create a new project

npm init

image.png

this is my configuration,
I'm using the main script as notifier.js.

now you need to install the packages and the steem package

npm i steem --save

image.png

Great, now create the notifier.js script
image.png

now add the steem library

let steem = require('steem');

now create a new variable called account which will be the account that gets the notification

// The account that gets the notification
let account = "@lonelywolf";

now use the streamTransactions function to get new transactions through the blockchain

steem.api.streamTransactions('head', function(err, result) { 

});

now we need to get the type of the transaction

 // transaction type, the type of the transaction
let type = result.operations[0][0];

we're getting the type of the transaction from the object of the operations on the result

same for data, we're getting the data of the transaction

// transaction data, the data that comes with the transaction
let data = result.operations[0][1]; 

now we need to check if the transaction is a comment (a comment can be a comment or a post)

if(type == "comment"){

}

great now we need to get the body of the comment

let body = data.body;

cool, now we need to check if the body includes our account name (@Lonelywolf)

if(body.includes(account)){

}

and now all we need to do is to send logs to the console,
for you, you can make a site that "pushing" notifications on the bell for example on steempeak is on the bell beside to your account
image.png

because we're in a basic tutorial I will just send console logs

console.log(account + " You got new notification!");
console.log("URL: " + "https://steemit.com/@" + data.author + "/" + data.permlink);
console.log("Notification delivered by @lonelywolf notifier.js");

results:
image.png

and yes, the URL works perfect, you can check it out
https://steemit.com/@lonelywolf/pssoem

Here we're done!
this is a basic tutorial and easy tutorial!

Proof of Work Done

https://github.com/upmeboost-utopian

Have a great day!

Sort:  

Thank you for your contribution @lonelywolf.
After reviewing your tutorial we suggest the following points listed below:

  • Your tutorial is quite short for a good tutorial. We recommend you aim for capturing at least 2-3 concepts.

  • Using the first person in the tutorials makes it difficult to understand the tutorials. We suggest using the third person in your text.

  • You need to further detail your tutorials. Beyond practice it is important to have the theory in a tutorial.

Thank you for your work in developing this tutorial.
Looking forward to your upcoming tutorials.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Chat with us on Discord.

[utopian-moderator]

Thanks I will use the suggestions for next tutorial!

Thank you for your review, @portugalcoin! Keep up the good work!

Nice job on this post, but sorry this is not weedcash related.

I'm sorry I didn't knew that I can't bring other content, I will not upload these tutorials to weedcash, thanks and sorry

Hi, @lonelywolf!

You just got a 0.18% upvote from SteemPlus!
To get higher upvotes, earn more SteemPlus Points (SPP). On your Steemit wallet, check your SPP balance and click on "How to earn SPP?" to find out all the ways to earn.
If you're not using SteemPlus yet, please check our last posts in here to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.

Hi @lonelywolf!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Hey, @lonelywolf!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Oh wow, thanks this is actually very helpful!

Thank you!
I will not continue sharing that posts in weedcash so you can follow me on steemit, palnet and SteemCoinPan :)

Coin Marketplace

STEEM 0.31
TRX 0.12
JST 0.033
BTC 64605.91
ETH 3159.61
USDT 1.00
SBD 4.11