0
votes

I want to use IncomingWebhook api of @slack/client in aws lambda function. There is something problems in my code. Please notice me how can I use.

This is my code below

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

exports.handler = (event, context, callback) => {
  const webhook = new IncomingWebhook(config.slack.webHookUrl)
  webhook.send('Hello there', function(err, res) {
    if (err) {
        console.log('Error:', err);
        context.fail('fail')
    } else {
        console.log('Message sent: ', res);
        context.succeed('succeed')
    }
  });
}

And This is my errors

{
  "errorMessage": "RequestId: 9e1b4362-259d-11e8-b422-91108e46ebe1
                    Process exited before completing request"
}

Here is console errors

START RequestId: 9e1b4362-259d-11e8-b422-91108e46ebe1 Version: $LATEST 2018-03-12T02:32:33.215Z 9e1b4362-259d-11e8-b422-91108e46ebe1 TypeError: Cannot set property 'text' of undefined at IncomingWebhook.send (/var/task/node_modules/@slack/client/dist/IncomingWebhook.js:26:26) at exports.handler (/var/task/index.js:6:11) END RequestId: 9e1b4362-259d-11e8-b422-91108e46ebe1 REPORT RequestId: 9e1b4362-259d-11e8-b422-91108e46ebe1 Duration: 85.31 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 31 MB
RequestId: 9e1b4362-259d-11e8-b422-91108e46ebe1 Process exited before completing request

1

1 Answers

0
votes

This was due to a bug in the Slack client which was reported here: https://github.com/slackapi/node-slack-sdk/issues/479, and subsequently fixed in https://github.com/slackapi/node-slack-sdk/releases/tag/v4.0.1. A simple upgrade to the latest version (v4.3.1 at the time of writing) will fix this.