I've created a slack bot that calls a lambda handler. The function in lambda checks the received text and sends back a message to slack bot. For some reason the slack bot keeps retrying three times since it thinks it doesn't get a callback so the replied message gets printed in slack three times. I've tried using a callback instead of a http post request but that doesn't seem to work either. Does anyone know how to stop slack bot from calling the lambda again and again? I've commented out the callback since it doesn't work.
function sendToSlack (messages, callback) {
return new Promise((resolve, reject) => {
// callback(null, {
// statusCode: 200,
// body: JSON.stringify({"text": "Hello"})
// })
// return resolve()
let httpReq = http.request(slackHookReqObj, (res) => {
resolve()
})
httpReq.on('error', reject)
httpReq.write(JSON.stringify({ "text": messages.join('\n') }))
httpReq.end()
})
}
async function test (event, context, callback) {
return new Promise(async (resolve, reject) => {
let slackEvent = JSON.parse(event.body)
if (slackEvent.event.type === 'app_mention') {
if (receivedText[1] == 'help') {
var helpMessages = ['test']
if (helpMessages.length) await sendToSlack(helpMessages, callback)
}
}
return resolve()
})
}
exports.handler = test