'client is null on app.action in Slack both using Bolt for Javascript

I'm developing a Slack bot using Glitch and Bolt for Javascript.

I'm opening a Model with two button (Approve and Reject), everything works up to where the user clicks on Approve and the app.action is reached but client is null and I need to send it to the next method...What can be missing?

This is the message I'm sending to a user after selecting everything in a dialog

async function sendSlackMessageToLead(requesterUsername, requesterSlackId, submittedValues, client, logger, leadUsername, leadId){
  try {
    await client.chat.postMessage({
      channel: leadId,
      text: "New PTO Request from " + requesterUsername,
      blocks: [
        {
          type: "header",
          text: {
            type: "plain_text",
            text: "You have requested a new PTO",
          },
        },
        {
          type: "section",
          fields: [
            {
              type: "mrkdwn",
              text:
                "*Type:*\n" +
                  submittedValues.type_block.type.selected_option.text !=
                null
                  ? submittedValues.type_block.type.selected_option.text.text
                  : "N/A",
            },
            {
              type: "mrkdwn",
              text: "*Created by:*\n<@" + requesterUsername + ">",
            },
          ],
        },
        {
          type: "section",
          fields: [
            {
              type: "mrkdwn",
              text:
                "*When:*\n" +
                "From " +
                submittedValues.startdate.datepicker_action_start_date
                  .selected_date +
                " \nTo      " +
                submittedValues.enddate.datepicker_action_end_date
                  .selected_date,
            },
          ],
        },
        {
          type: "section",
          fields: [
            {
              type: "mrkdwn",
              text:
                submittedValues.allDayBlock["checkboxes-action"]
                  .selected_options == ""
                  ? "All Day? No"
                  : "All Day? Yes",
            },
          ],
        },
        {
          type: "section",
          fields: [
            {
              type: "mrkdwn",
              text:
                "*Hours:*\n" +
                submittedValues.starttime.timepicker_action_start_time
                  .selected_time +
                " - " +
                +submittedValues.endtime.timepicker_action_end_time
                  .selected_time,
            },
            {
              type: "mrkdwn",
              text: "*Remaining balance:*\n32.0 hours (4 days)",
            },
          ],
        },
         {
          type: "actions",
          block_id: "approved_by_firstone_block",
          elements: [
            {
              type: "button",
              text: {
                type: "plain_text",
                emoji: true,
                text: "Approve",
              },
              style: "primary",
              value: JSON.stringify(submittedValues),
              action_id: "approved_by_firstone_click"
            },
            {
              type: "button",
              text: {
                type: "plain_text",
                emoji: true,
                text: "Deny",
              },
              style: "danger",
              value: JSON.stringify(submittedValues),
              action_id: "rejected_by_firstone_click"
            },
          ],
        },
      ],
    });
  } catch (error) {
    logger.error("Error while sending message to lead: " + error);
  }
}

Here clientSlack is undefined, the rest of the parameter have values in them

app.action({ action_id: 'approved_by_firstone_click', block_id: 'approved_by_firstone_block' }, async ({ body, clientSlack, ack, logger }) => {
  // Acknowledge the action
  await ack();
  console.log ("approved_by_firstone_click");
  console.log ("body: " + JSON.stringify(body));
  console.log ("ack: " + ack);
  console.log ("clientSlack: " + JSON.stringify(clientSlack));
  console.log ("logger: " + JSON.stringify(logger));
  var submittedValues = JSON.parse(body.actions[0].value);
  
  await sendSlackMessageToNextPerson(body.user.username, submittedValues, clientSlack, logger, "name.surname", "SlackId");
});

Thanks in advance. Guillermo.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source