Telegram Reply Bot Update

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@r351574nc3·
0.000 HBD
Telegram Reply Bot Update
# 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

```patch
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. 

```patch
@@ -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.

```patch
@@ -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
----
* [Submit Pull Request](https://github.com/r351574nc3/steem-bot-examples/pulls)
* [Submit Issue](https://github.com/r351574nc3/steem-bot-examples/issues)

[r351574nc3#7016 on discord](https://discord.gg/ZVXCmcW)

[Steem Development on Telegram](https://t.me/joinchat/G3o-LBKYr7FPwFP-gaeqFg)

<br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@r351574nc3/telegram-reply-bot-update">Utopian.io -  Rewarding Open Source Contributors</a></em><hr/>
👍 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,