How do you send slack messages to a specific user?

Are you using our SaaS platform (Baserow.io) or self-hosting Baserow?

Self-hosted

If you are self-hosting, what version of Baserow are you running?

Baserow API spec (2.0.3)

What are the exact steps to reproduce this issue?

I am trying to setup a slack integration that sends a message to a specific user given an event. The Baserow documentation says that the “Send a Slack message” automation supports providing a Slack UserID “Channel: Choose the channel name or User ID to receive the message.” but when I populate a UserID I get an error “The channel #**** was not found.”.

Attach screenshots, videos, or logs that demonstrate the issue.

hi @epanipinto - We currently don’t natively support sending a DM to a specific user. I’ve created a feature request issue for this: Send Slack Direct Messages (DM) · Issue #4469 · baserow/baserow · GitHub

You may be able to work around this by also adding the im:write scope to your app, but I’m not 100% sure if this will work.

Hi @paljort,

Thanks for the reply. I tried adding the im:write scope to my app but still got the same error message. I found a work around for now. Using the Send an HTTP Request action I am calling https://slack.com/api/chat.postMessage with the Authorization Bearer <token> header I am able to pass a json body that messages a user directly. The next issue I am having is trying to add logic to the Body content to pass json while Use advanced input seem to invalidate the json content.

1 Like

Hi @epanipinto , thanks for sharing your workaround. I just ran into the same issue and also worked around it with the HTTP Request action, but I’m using a Slack webhook endpoint to a specific channel instead of the chat API.

Were you able to get the dynamic body content working? I also had problems with the body being invalid JSON when trying to merge in row data at first.

In my case, it was the line returns within the JSON causing the issue. I replaced them with \n for new lines, and now I’m able to post dynamic messages to slack that tag users and include row data.

You can tag users using their ID in the message text, in the format <@USER_ID>. I’ve started storing the IDs in the employee table with the extra <@ and > around the ID to make it easier to reference and insert in messages.

@greenflux I’m still playing around with it but not successfully. The way the application processes the json is really frustrating as I think its adding characters when it sends the body and does not give you a clear error message when you have invalid json. @paljort It would be nice if the error showed you the changes its making to your json content so we could work with the application instead of against it. I also haven’t had much luck switching between the normal input and advanced input either.

While I haven’t quite figured out why it works this way but something with the line breaks and leading spaces or tabs invalidates the json. I have had the most success by keeping things on a single line and using “\n” like you said. When I keep it simple ex: ​{“channel”: “”, "“text”: "“} this seems to work, most of the time, but I am trying to use slack blocks Block Kit | Slack Developer Docs which require a more complex json structure and having a really hard time getting the json just right so that Baserow is happy with it.

@greenflux Are you putting your Authorization Bearer token in the the header? Have you found a way to hide it? I don’t love that I am storing it in plain text and that I have to reuse it everywhere.

@paljort Is there a way to hide or reuse variables within Baserow at an Application or Automation level?

@greenflux Oh also regarding tagging users I had this idea the other day calling the ​https://slack.com/api/users.list API and then populating a Slack Users table and the teams they are on. I have a similar flow for channels as well using https://slack.com/api/conversations.list. This has given me a lot more granular control on where to send messages for my workflows and allows us to tie slack ids to our personnel list.

1 Like

That’s a good idea on using the Slack API to get the list of users and IDs!

Are you putting your Authorization Bearer token in the the header? Have you found a way to hide it? I don’t love that I am storing it in plain text and that I have to reuse it everywhere.

I’m using an incoming webhook, not the main REST API, so there’s no authentication header needed.

I think the only way to securely store the Slack credentials on the server side is to use the native Baserow Slack integration, but then you can’t tag users.

Ah ya we have a webhook on a table so that when a row is created or a specific field changes that triggers the automation to run and there are several types of slack messages we want to send that could be to either a user or a group.

@epanipinto Would you mind sharing the JSON that you’re trying to post? In my case, I’m using this exact JSON and post’ing to the ​https://slack.com/api/chat.postMessage endpoint, and it works as expected:

{"channel":"#tsering-test","blocks":
[
  {
    "type": "header",
    "text": {
      "type": "plain_text",
      "text": "New request"
      }
  },
  {
    "type": "section",
    "fields": [
      {
        "type": "mrkdwn",
        "text": "*Type:*\nPaid Time Off"
      },
      {
        "type": "mrkdwn",
        "text": "*Created by:*\n<example.com|Fred Enriquez>"
      }
    ]
  },
  {
    "type": "section",
    "fields": [
      {
        "type": "mrkdwn",
        "text": "*When:*\nAug 10 - Aug 13"
      }
    ]
  },
  {
    "type": "section",
    "text": {
      "type": "mrkdwn",
      "text": "<https://example.com|View request>"
    }
  }
]}

@epanipinto We have discussed this and while we do want this in the future, it’s not on our immediate near-term road map.

@paljort Its been really inconsistent with what works and what doesn’t. I would say an ideal workflow for me would be to construct and format my json in VSCode and then copy and paste it into Baserow. I used the default example from Block Kit Builder but added channel. When I copied using Chrome from the Slack site to Baserow it says its valid but when I copy using Chrome from the Slack site to VSCode to Baserow I get invalid json.

Screenshots after copying from VSCode

Copied from VSCode to code block

{
  "channel": "U0*******",
  "blocks": [
    {
      "type": "section",
      "text": {
        "type": "mrkdwn",
        "text": "Hello, Assistant to the Regional Manager Dwight! *Michael Scott* wants to know where you'd like to take the Paper Company investors to dinner tonight.\n\n *Please select a restaurant:*"
      }
    },
    { "type": "divider" },
    {
      "type": "section",
      "text": {
        "type": "mrkdwn",
        "text": "*Farmhouse Thai Cuisine*\n:star::star::star::star: 1528 reviews\n They do have some vegan options, like the roti and curry, plus they have a ton of salad stuff and noodles can be ordered without meat!! They have something for everyone here"
      },
      "accessory": {
        "type": "image",
        "image_url": "https://s3-media3.fl.yelpcdn.com/bphoto/c7ed05m9lC2EmA3Aruue7A/o.jpg",
        "alt_text": "alt text for image"
      }
    },
    {
      "type": "section",
      "text": {
        "type": "mrkdwn",
        "text": "*Kin Khao*\n:star::star::star::star: 1638 reviews\n The sticky rice also goes wonderfully with the caramelized pork belly, which is absolutely melt-in-your-mouth and so soft."
      },
      "accessory": {
        "type": "image",
        "image_url": "https://s3-media2.fl.yelpcdn.com/bphoto/korel-1YjNtFtJlMTaC26A/o.jpg",
        "alt_text": "alt text for image"
      }
    },
    {
      "type": "section",
      "text": {
        "type": "mrkdwn",
        "text": "*Ler Ros*\n:star::star::star::star: 2082 reviews\n I would really recommend the  Yum Koh Moo Yang - Spicy lime dressing and roasted quick marinated pork shoulder, basil leaves, chili & rice powder."
      },
      "accessory": {
        "type": "image",
        "image_url": "https://s3-media2.fl.yelpcdn.com/bphoto/DawwNigKJ2ckPeDeDM7jAg/o.jpg",
        "alt_text": "alt text for image"
      }
    },
    { "type": "divider" },
    {
      "type": "actions",
      "elements": [
        {
          "type": "button",
          "text": { "type": "plain_text", "text": "Farmhouse", "emoji": true },
          "value": "click_me_123"
        },
        {
          "type": "button",
          "text": { "type": "plain_text", "text": "Kin Khao", "emoji": true },
          "value": "click_me_123",
          "url": "https://google.com"
        },
        {
          "type": "button",
          "text": { "type": "plain_text", "text": "Ler Ros", "emoji": true },
          "value": "click_me_123",
          "url": "https://google.com"
        }
      ]
    }
  ]
}

Copied from Baserow to a code block:

concat('{', '  "channel": "U0*******",', '  "blocks": [', '    {', '      "type": "section",', '      "text": {', '        "type": "mrkdwn",', '        "text": "Hello, Assistant to the Regional Manager Dwight! *Michael Scott* wants to know where you\'d like to take the Paper Company investors to dinner tonight.\n\n *Please select a restaurant:*"', '      }', '    },', '    { "type": "divider" },', '    {', '      "type": "section",', '      "text": {', '        "type": "mrkdwn",', '        "text": "*Farmhouse Thai Cuisine*\n:star::star::star::star: 1528 reviews\n They do have some vegan options, like the roti and curry, plus they have a ton of salad stuff and noodles can be ordered without meat!! They have something for everyone here"', '      },', '      "accessory": {', '        "type": "image",', '        "image_url": "https://s3-media3.fl.yelpcdn.com/bphoto/c7ed05m9lC2EmA3Aruue7A/o.jpg",', '        "alt_text": "alt text for image"', '      }', '    },', '    {', '      "type": "section",', '      "text": {', '        "type": "mrkdwn",', '        "text": "*Kin Khao*\n:star::star::star::star: 1638 reviews\n The sticky rice also goes wonderfully with the caramelized pork belly, which is absolutely melt-in-your-mouth and so soft."', '      },', '      "accessory": {', '        "type": "image",', '        "image_url": "https://s3-media2.fl.yelpcdn.com/bphoto/korel-1YjNtFtJlMTaC26A/o.jpg",', '        "alt_text": "alt text for image"', '      }', '    },', '    {', '      "type": "section",', '      "text": {', '        "type": "mrkdwn",', '        "text": "*Ler Ros*\n:star::star::star::star: 2082 reviews\n I would really recommend the  Yum Koh Moo Yang - Spicy lime dressing and roasted quick marinated pork shoulder, basil leaves, chili & rice powder."', '      },', '      "accessory": {', '        "type": "image",', '        "image_url": "https://s3-media2.fl.yelpcdn.com/bphoto/DawwNigKJ2ckPeDeDM7jAg/o.jpg",', '        "alt_text": "alt text for image"', '      }', '    },', '    { "type": "divider" },', '    {', '      "type": "actions",', '      "elements": [', '        {', '          "type": "button",', '          "text": { "type": "plain_text", "text": "Farmhouse", "emoji": true },', '          "value": "click_me_123"', '        },', '        {', '          "type": "button",', '          "text": { "type": "plain_text", "text": "Kin Khao", "emoji": true },', '          "value": "click_me_123",', '          "url": "https://google.com"', '        },', '        {', '          "type": "button",', '          "text": { "type": "plain_text", "text": "Ler Ros", "emoji": true },', '          "value": "click_me_123",', '          "url": "https://google.com"', '        }', '      ]', '    }', '  ]', '}')

Copied from Baserow without a code block

{

“channel”: “U0*******”,

“blocks”: [

{

  "type": "section",

  "text": {

    "type": "mrkdwn",

    "text": "Hello, Assistant to the Regional Manager Dwight! \*Michael Scott\* wants to know where you'd like to take the Paper Company investors to dinner tonight.\\n\\n \*Please select a restaurant:\*"

  }

},

{ "type": "divider" },

{

  "type": "section",

  "text": {

    "type": "mrkdwn",

    "text": "\*Farmhouse Thai Cuisine\*\\n:star::star::star::star: 1528 reviews\\n They do have some vegan options, like the roti and curry, plus they have a ton of salad stuff and noodles can be ordered without meat!! They have something for everyone here"

  },

  "accessory": {

    "type": "image",

    "image_url": "https://s3-media3.fl.yelpcdn.com/bphoto/c7ed05m9lC2EmA3Aruue7A/o.jpg",

    "alt_text": "alt text for image"

  }

},

{

  "type": "section",

  "text": {

    "type": "mrkdwn",

    "text": "\*Kin Khao\*\\n:star::star::star::star: 1638 reviews\\n The sticky rice also goes wonderfully with the caramelized pork belly, which is absolutely melt-in-your-mouth and so soft."

  },

  "accessory": {

    "type": "image",

    "image_url": "https://s3-media2.fl.yelpcdn.com/bphoto/korel-1YjNtFtJlMTaC26A/o.jpg",

    "alt_text": "alt text for image"

  }

},

{

  "type": "section",

  "text": {

    "type": "mrkdwn",

    "text": "\*Ler Ros\*\\n:star::star::star::star: 2082 reviews\\n I would really recommend the  Yum Koh Moo Yang - Spicy lime dressing and roasted quick marinated pork shoulder, basil leaves, chili & rice powder."

  },

  "accessory": {

    "type": "image",

    "image_url": "https://s3-media2.fl.yelpcdn.com/bphoto/DawwNigKJ2ckPeDeDM7jAg/o.jpg",

    "alt_text": "alt text for image"

  }

},

{ "type": "divider" },

{

  "type": "actions",

  "elements": \[

    {

      "type": "button",

      "text": { "type": "plain_text", "text": "Farmhouse", "emoji": true },

      "value": "click_me_123"

    },

    {

      "type": "button",

      "text": { "type": "plain_text", "text": "Kin Khao", "emoji": true },

      "value": "click_me_123",

      "url": "https://google.com"

    },

    {

      "type": "button",

      "text": { "type": "plain_text", "text": "Ler Ros", "emoji": true },

      "value": "click_me_123",

      "url": "https://google.com"

    }

  \]

}

]

}

@epanipinto Thanks for sharing more context.

There are two scenarios you describe.

The first scenario should definitely work. I’ve repeated the following steps, which result in a Slack message successfully being sent:

  • Copied the example blocks example from the Slack block kit examples
  • Pasted the example into my VSCode
  • Added {"channel": "#tsering-test", to the beginning of the example, and added } at the end of the JSON to make the payload valid JSON
  • Copy/pasted this into the Baserow Body Content field

When I test the node, I see the request is successful and the message is visible in Slack.

If this exact flow isn’t working for you, I wonder if VSCode is somehow modifying the data (perhaps a linter or plugin is modifying the data?). Can you try copying the value from VSCode into a tool like https://jsonlint.com/ to validate your JSON?

The second scenario you describe is copying data from the Baserow input field. This happens because of the line breaks in your JSON. When you type something in the Baserow input, the text is converted into a formula, and because of the line breaks, we end up with the concat(). I’ve created an issue for this. For now, unfortunately you’ll have to validate your JSON outside of the Baserow input.