Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postMessageToUser does not Work #137

Open
kodekage opened this issue Sep 27, 2019 · 1 comment
Open

postMessageToUser does not Work #137

kodekage opened this issue Sep 27, 2019 · 1 comment

Comments

@kodekage
Copy link

kodekage commented Sep 27, 2019

I'm currently building a bot and i'm trying to handle a message event, such that when there is a message on a channel which includes a help string the bot sends a message to a user.

I have being trying to achieve this using bot.postMessageToUser('username', 'hello i am bot', params) and it's not working 😄

I saved that expression in a variable like:

const postToUser = bot.postMessageToUser(
    'hic',
    'hello i am dionysus',
    params
  );

I used an if statement to check if it actually works:

if(postToUser){
    console.log("Posted to the User");
  }

Unexpectedly it logs Posted to User When it actually does not on slack

Please how can i resolve this or still achieve my goal? I'd really appreciate all the help i can get

I'm using "slackbots": "^1.2.0"

@a007mr
Copy link

a007mr commented Oct 5, 2019

I have the same problem. bot.postMessageToUser(user, message) doesn't work.

My code:

bot.on('message', data => {
  if (data.type !== 'message' || data.subtype === 'bot_message') {
    return;
  }

  handleMessage(data);
});

function handleMessage(data) {
  let user = data.user;     // I tried also user data.client_msg_id
  console.log(`user`, user);    // it shows somethings like `user UP23WKQXX`
  let message = data.text;

  if (message.includes(' help')) {
    runHelp(user);
  }
}

function runHelp(user) {
  bot.postMessageToUser(user, `message`);
}

bot.postMessageToUser(user, message) doesn't work. It gives error Assertion failed: user not found.

How to get user name?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants