p0o / steem-bot

Easy automation on top of Steem blockchain
MIT License
53 stars 40 forks source link

Why is in the responder no category #1

Closed smike18 closed 6 years ago

smike18 commented 7 years ago

HI, I think it is important to add the category from the targetPost like this

var Responder = function () {
  function Responder(_ref) {
    var targetUsername = _ref.targetUsername,
        targetPermlink = _ref.targetPermlink,
        transferMemo = _ref.transferMemo,
        responderUsername = _ref.responderUsername,
        postingKey = _ref.postingKey,
        activeKey = _ref.activeKey,
->    targetCategory = _ref.targetCategory;

    _classCallCheck(this, Responder);

    this.targetUsername = targetUsername;
    this.targetPermlink = targetPermlink;
    this.transferMemo = transferMemo;
    this.responderUsername = responderUsername;
    this.postingKey = postingKey;
    this.activeKey = activeKey;
->this.targetCategory = targetCategory;
  }

How can I implement this?

PS: Very nice bot for beginners, Thanks

p0o commented 7 years ago

You want to set a category (in steem api it's called tag) in jsonMetadata for the comments that bot is sending right?

So you can use comment like this:

responder.comment(`Hi @${data.author} there! I just upvoted you using SteemBot JavaScript library!`, {tag: 'game'});

Let me know if it's what you mean. In that case I think it would be a really good addition since some developers need flexibility on what they store in jsonMetadata.

smike18 commented 7 years ago

Hi, thanks for the reply. no I want to send the person I´ve upvoted a 0.001 SBD message with the full url in the memo. But now I could only handle to send this

'https://steemit.com/' + undefined + '/@' + this.targetUsername + '/' + this.targetPermlink;

How can I put the category into the url?

Thanks for the help.

p0o commented 7 years ago

Good question. The thing is that stream api of Steem does not provide you all the data regarding the post and only some general information. If you need more data like tags or even the full url you should make another request to the node.

Right now steembot doesn't provide the full content data but if you import steem-js package in your code you can make a request like this in your steem-bot callback:

steem.api.getContentAsync(this.targetUsername, this.targetPermlink).then((content) => {
  console.log(content.url);
});
smike18 commented 7 years ago

Thanks for the answer. But I get an error message "url is not defined". I put the code in the Steembot folder and import steem. then function handleDeposit(data, responder) { responder.sendSdb(0.001, url)

}

p0o commented 7 years ago

Because url is not defined in that function. You should do it this way:

import steem from 'steem';

bot.onPost(handlePost);

function handlePost(data, responder) {
  steem.api.getContentAsync(this.targetUsername, this.targetPermlink).then((content) => {
    responder.sendSdb(0.001, content.url);
  });
}
smike18 commented 7 years ago

Hi thanks for the help but
it doesn't work. It sends the amount but the memo is empty.

I've tried different ways

bot.onPost(handlePost);

function handlePost(data, responder) {
  steem.api.getContentAsync(this.targetUsername, this.targetPermlink).then((content) => {
    responder.sendSbd(0.001, content.url);
  });
}

----or-----

bot.onPost(handleDeposit);

function handleDeposit(data, responder) {
  steem.api.getContentAsync(this.targetUsername, this.targetPermlink).then((content) => {
    responder.sendSbd(0.001, content.url);
  });
}

I always get the empty memo.

p0o commented 7 years ago

Do some debugging and add some console.log() to understand which variables are null. Probably username and permlink are not correct. Try to get them directly from data rather than using this. If still didn't work let me know so I update example folder with a working snippet.

BTW, both of your "different ways" are same just with different function name. Steem-bot doesn't care what function name you pass to it. handlePost and handleDeposit could be anything else.

smike18 commented 7 years ago

Hi thanks for the reply I made a console.log(data) output. The "Tag" is under "parent_permlink" but he doesn't want to write that tag in the memo field either.

I've tried this out.

bot.onPost(handlePost);

function handlePost(data, responder) {
  steem.api.getContentAsync(this.targetUsername, this.targetPermlink).then((content) => {
    responder.sendSbd(0.001, content.parent_permlink);
  });
}
bot.onPost(handlePost);

function handlePost(data, responder) {
  steem.api.getContentAsync(data.targetUsername, data.targetPermlink).then((content) => {
    responder.sendSbd(0.001, data.parent_permlink);
  });
}
bot.onPost(handlePost);

function handlePost(data, responder) {
  steem.api.getContentAsync(this.targetUsername, this.targetPermlink).then((content) => {
    responder.sendSbd(0.001, data.parent_permlink);
  });
}

Also here. All memos are empty but the transaction is made. The parent_permlink should at least be in the memo.

p0o commented 7 years ago

Sorry for getting back late. I just had some time to check if the memo API is working fine or not. I checked it both for sendSbd() and sendSteem() functions and both can send the memo correctly. Your problem is that you don't check your objects while sending and keep sending empty strings in your transactions.

Not sure how you setup your environment but this.targetUsername doesn't exist for me. It's also not part of the API I introduced in examples. This code perfectly work for me and send me the full URL as memo:

// the fact that I triggered only my username is irrelevant to solution
bot.onPost('p0o-dev', handlePost);

function handlePost(data, responder) {
  steem.api.getContentAsync(data.author, data.permlink).then((content) => {
    console.log(content);
    responder.sendSbd(0.001, 'https://steemit.com' + content.url);
  });
}

bot.start();