Telegram Reply Bot Update

in #utopian-io7 years ago (edited)

New Features

Beneficiary Support

Now the user running the bot can use the beneficiary feature of steemit to allow the bot owner to obtain rewards on comments upvoted from the bot. The purpose of this is so that the bot owner can recoup expenses due to running the bot from those that use it. The default reward is 25%.

This was implemented by using the comment_options operation on transactions in the steem blockchain.

Changes

diff --git a/telegram-reply-steem-bot/src/helpers/bot/notify.ts b/telegram-reply-steem-bot/src/helpers/bot/notify.ts
index 3bbc86d..44dbe8b 100644
--- a/telegram-reply-steem-bot/src/helpers/bot/notify.ts
+++ b/telegram-reply-steem-bot/src/helpers/bot/notify.ts
@@ -129,10 +129,10 @@ function handle_reply_to_bot(ctx: any) {
                     + "-" + new Date().toISOString().replace(/[^a-zA-Z0-9]+/g, "").toLowerCase();
 
                 steem.broadcast.commentAsync(
-                    wif,
+                    ctx.wif,
                     message.author, // Leave parent author empty
                     message.permlink,
-                    user, // Author
+                    ctx.user, // Author
                     permlink, // Permlink
                     permlink, // Title
                     ctx.message.text, // Body

Originally, the bot runner would be used to post replies. This allows the /start command to specify for a given chat who to reply as. This requires a private posting key to match the author for verification.

@@ -149,6 +149,27 @@ function handle_reply_to_bot(ctx: any) {
                     });
                     return result;
                 })
+                .then((result: any) => {
+                    const extensions = [
+                        [
+                            0,
+                            {
+                                beneficiaries: [
+                                    {
+                                        account: user,
+                                        weight: 2500
+                                    }
+                                ]
+                            }
+                        ]
+                    ];
+                    return steem.broadcast.commentOptionsAsync(ctx.wif, ctx.user,
+                    permlink,
+                    "1000000.000 SBD", 10000, true, false, [])
+                    .catch((err: any) => {
+                        console.log("Unable to set beneficiaries ", JSON.stringify(err));
+                    });
+                })
                 .catch((err: any) => {
                     console.log("Unable to process comment. ", err);
                 });

This is the implementation of the comment_options operation which adds the beneficiary as the user running the bot.

@@ -223,7 +244,7 @@ function handle_reply_to_user(comment: Comment) {
 
 function find_handler_for(user: string): Promise<CommentEmitter> {
     return Promise.filter(HANDLERS,
-            (handler: CommentEmitter, index: number, length: number) => handler.user == user)
+            (handler: CommentEmitter, index: number, length: number) => handler.context.user == user)
             .then((handlers) => {
                 if (handlers && handlers.length > 0) {
                     return Promise.resolve(handlers.pop());
@@ -267,8 +288,8 @@ export let execute = () => {
 
         return parse_start_command(ctx.message.text)
             .then((args: any) => {
-                handler.user = args.user;
-                handler.wif = args.wif;
+                handler.context.user = args.user;
+                handler.context.wif = args.wif;
                 HANDLERS.push(handler);
                 return ctx.reply(`Welcome ${args.user}!`);
             },

The user and private posting key are moved into the context where they are more accessible by the calling functions.

Roadmap

  • Up/downvoting of replies from telegram!

Contributing


r351574nc3#7016 on discord

Steem Development on Telegram



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Great contribution.

PS: Don't buy upvotes for your post. LOL

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Hey @r351574nc3 I am @utopian-io. I have just upvoted you!

Achievements

  • WOW WOW WOW People loved what you did here. GREAT JOB!
  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.18
TRX 0.15
JST 0.029
BTC 62907.73
ETH 2531.30
USDT 1.00
SBD 2.62