How to call an action through a button sent on a sendMessage API block?

Hello – I am posting this here in the hopes that someone has already faced this issue. Its seems pretty basic but I was not able to find the solution in the documentation, GitHub or even Google. Thanks in advance.

Description

I am using Rocket.Chat and I can send messages to my room through the REST API endpoint

http://localhost:3000/api/v1/chat.sendMessage

The message is sent to my board allright, and I am sending a button element in it, using this payload:

{
    "message": {
        "rid": "WAgEFZBAYqrjMvY5f",
        "blocks": [
            {
                "type": "section",
                "accessory": {
                    "type": "button",
                    "text": {
                        "type": "plain_text",
                        "text": "CLICK ME"
                    },
                    "actionId": "action_1",
                    "style": "danger"
                }
            }
        ]
    }
}

In my custom app, I am setting a executeBlockActionHandler method in the main ts file, but whenever I click on the button sent in the message, I receive the following message in my terminal:

rocketchat            | App true triggered an interaction but it doen't exist or doesn't have method executeBlockActionHandler

How can I get this click on my message button? Do I have to register it somehow? I couldn’t find anything in the documentation so far, since it seems that all examples deal with buttons added through the app itself, not the RESP API message.

Server Setup Information

  • Version of Rocket.Chat Server: 6.0.0
  • Operating System: Linux PopOS
  • Deployment Method: docker
  • Number of Running Instances: 1
  • NodeJS Version: 16.17.0
  • MongoDB Version: 6.0.4

Hi! Welcome to our community! :hugs:

I replicated the issue, and I have a guess on what it might be.

It is not finding the related app to send the action to. As it was triggered by a non app api.

What you can do is register an API in your app, and use it instead. That way the message sent will have your app listening to that interaction.

By the way, that is a nice thing to add to our Demo.App, if you are interested in contributing :slight_smile:

Hey @dudanogueira, thank you so much for your input! I will definitely give it a try and contribute if possible. I will let you know. Cheers!

1 Like