done(err)

The done(err) function signals to the platform that the script is complete. It must be called any time script execution ends.

Wait for asynchronous operations

Make sure all asynchronous operations are complete before calling done() by using the await prefix. This does not apply to startTyping() or stopTyping().

Parameter Type Required Description
err Object<Error> Optional

An error to pass to the platform. See https://nodejs.org/api/errors.html for more information on error objects.

if (bot.user.firstName) {
   await bot.channel.sendTextMessage(`Hello ${bot.user.firstName}`, params);
} else {
   await  bot.channel.sendTextMessage(`Hello there`, params);
}

done();

Make sure done() is used anywhere the script execution ends:

try {
  const response = await axios.get('https://api.chucknorris.io/jokes/random', { json: true });
  await bot.channel.sendTextMessage('😂😆 ' + response.data.value, params);
  done();
} catch (err) {
  await bot.channel.sendTextMessage('uh oh, something went wrong', params);
  done(err);
}
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Article is closed for comments.