1

I am using chat.postMessage with attachments to send a direct message to a Slack User.

In attachment I have a button and I wanted to change label (text) of this button based on the Slack user language preference.

Is there any way to achieve this?

Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114
MaKeer
  • 61
  • 6

1 Answers1

1

Yes. A couple of Slack API methods have an optional locale feature. By calling them with the include_locale property set to true they will return the locale information.

The locale field is a string containing a IETF language code, such as en-US, fr-FR, es-ES, or de-DE, and other future values.

Here is a list of Slack API methods supporting the locale feature:

  • channels.info
  • conversations.info
  • groups.info
  • im.info
  • im.open
  • rtm.start
  • users.info
  • users.list

So for your case you would first call users.info for the user to find out his correct locale and then compose your text accordingly.

Check out this offical post for full details on locale support by the Slack API.

Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114