botmasterai / botmaster-fulfill

a text-friendly way to integrate actions with your bot. Supply an object of action-functions that can return synchronously or asynchronously and replace text in the response, generate new responses, or do what the response claims to do.
MIT License
4 stars 2 forks source link

does not work with async / await #14

Open jwickens opened 7 years ago

jwickens commented 7 years ago

the following code does not work because it sees it as a promise waiting for fulfill to resolve, so nothing happens.

  image: { // send an image
    controller: async (params, next) => {
      // remove tag from current message and wait for it to be sent
      await next(null, '')
      // now send image
      let url
      if (params.content.startsWith('http')) {
        url = params.content
      } else {
        url = urlBase + params.content
      }
      const message = params.bot.createOutgoingMessageFor(params.update.sender.id)
      message.addAttachmentFromUrl('image', url)
      params.bot.sendMessage(message)
    }
  }