<commit_before>const messageTypesToDiscard = ['request_start_conversation', 'say_something', 'postback']

if (messageTypesToDiscard.includes(event.type)) {
  event.setFlag(bp.IO.WellKnownFlags.SKIP_DIALOG_ENGINE, true)

  if (event.type === 'say_something' && event.payload.text) {
    saySomething()
  }

  if (event.type === 'postback') {
    bp.logger.warn(`Just received a postback event: ${event.payload}. 
    To handle these kind of events. you need to create a hook that will process them.
    Please refer to the documentation here: https://botpress.io/docs/build/code/#hooks`)
  }
}

async function saySomething() {
  const text = event.payload.text

  if (text.startsWith('#!')) {
    /**
     * Sends an existing content element. Event is specified twice, since the first parameters are the
     * element arguments, and the second one is the event destination (required fields: botId, target, threadId, channel)
     */
    const content = await bp.cms.renderElement(text, event, event)
    await bp.events.replyToEvent(event, content)
  } else {
    // Sends a basic text message
    const payloads = await bp.cms.renderElement('builtin_text', { text, typing: true }, event.channel)
    await bp.events.replyToEvent(event, payloads)
  }
}
<commit_msg>fix async hook<commit_after>const messageTypesToDiscard = ['request_start_conversation', 'say_something', 'postback']

if (messageTypesToDiscard.includes(event.type)) {
  event.setFlag(bp.IO.WellKnownFlags.SKIP_DIALOG_ENGINE, true)

  if (event.type === 'postback') {
    bp.logger.warn(`Just received a postback event: ${event.payload}. 
    To handle these kind of events. you need to create a hook that will process them.
    Please refer to the documentation here: https://botpress.io/docs/build/code/#hooks`)
  }
}

const saySomethingHook = async () => {
  const text = event.payload.text

  if (event.type === 'say_something' && text && text.length) {
    if (text.startsWith('#!')) {
      /**
       * Sends an existing content element. Event is specified twice, since the first parameters are the
       * element arguments, and the second one is the event destination (required fields: botId, target, threadId, channel)
       */
      const content = await bp.cms.renderElement(text, event, event)
      await bp.events.replyToEvent(event, content)
    } else {
      // Sends a basic text message
      const payloads = await bp.cms.renderElement('builtin_text', { text, typing: true }, event.channel)
      await bp.events.replyToEvent(event, payloads)
    }
  }
}

return saySomethingHook()

{'fraction_non_alphanumeric': 0.11673151750972763, 'fraction_numerical': 0.0, 'mean_word_length': 3.761111111111111, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5327782', 'n_tokens_mistral': 775, 'n_tokens_neox': 759, 'n_words': 226}