Node-slack-sdk: webhhok with link_names does not create a mention

Created on 6 May 2018  路  2Comments  路  Source: slackapi/node-slack-sdk

Description

I'm sending a message to a channel using a webhook.
I'm setting link_names: true but userss are not mentioned.

What type of issue is this? (place an x in one of the [ ])

  • [x] bug
  • [ ] enhancement (feature request)
  • [x] question
  • [ ] documentation related
  • [ ] testing related
  • [ ] discussion

Requirements (place an x in each of the [ ])

  • [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [x] I've read and agree to the Code of Conduct.
  • [x] I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

@slack/client version: 4.2.0

node version: 8.9

OS version(s): OSX and Linux (Alpine)

Steps to reproduce:

  1. Send a message by webhook:
const {IncomingWebhook} = require('@slack/client');
const webhook = new IncomingWebhook('https://my-webhook-url');
webhook.send({text: 'some content @user1.last', link_names: true}, (err, result) => {
  if (err) {
    // report error
    retrun;
  }
  // report success
});

Expected result:

The message is sent to the channel and user.last is mentioned.

Actual result:

Message is sent, but the string user1.last is a plain text, not a mention and not clickable.

Thanks for the help!

question

All 2 comments

@royts i just tried to reproduce this issue and was not able to. i had to slightly modify your example because it looked like there's a typo retrun instead of return. also, i added logging to see the result. could you make the same changes and let me know if you're still having a problem?

const { IncomingWebhook } = require('@slack/client');

const webhook = new IncomingWebhook('https://hooks.slack.com/services/XXXXXXXXX');

webhook.send({text: 'some content @ankur', link_names: true}, (err, result) => {
  if (err) {
    // report error
    console.log(err);
    return;
  }
  // report success
  console.log(result);
});

another issue to check is if you actually have the right username, because Slack is saying farewell to usernames in favor of localizable and easier to personalize display names. i recommend you reconsider using the link_names option at all. its tied to the now outdated concept of usernames, so especially if this is new code, you should instead try to create mentions from user IDs. if you need help with how to achieve that, let me know!

hi @aoberoi - thanks for your answer.
I tried to use use ID (according to this: https://api.slack.com/changelog/2017-09-the-one-about-usernames#prepare) and it works great.
Thank you for that.

Was this page helpful?
0 / 5 - 0 ratings