<commit_before>'use strict'
const _ = require('lodash')
const INTENT_PREFIX = 'intent:'

/**
 * Get a variable under this user's storage
 * @title Validate user choice
 * @category Skills
 * @hidden true
 * @author Botpress, Inc.
 * @param {string} data - The parameters of the available choices
 */
const validateChoice = async data => {
  let choice = undefined
  const config = await bp.config.getModuleConfigForBot('basic-skills', event.botId)
  const nb = _.get(event.preview.match(/^[#).!]?([\d]{1,2})[#).!]?$/), '[1]')

  if (config.matchNumbers && nb) {
    const index = parseInt(nb) - 1
    const element = await bp.cms.getContentElement(event.botId, data.contentId)
    choice = _.get(element, `formData.choices.${index}.value`)
  }

  if (!choice && config.matchNLU && typeof _.get(event.nlu, 'intent.is') === 'function') {
    choice = _.findKey(data.keywords, keywords => {
      const intents = keywords
        .filter(x => x.toLowerCase().startsWith(INTENT_PREFIX))
        .map(x => x.substr(INTENT_PREFIX.length))
      return _.some(intents, k => event.nlu.intent.is(k))
    })
  }

  if (!choice) {
    choice = _.findKey(data.keywords, keywords =>
      _.some(
        keywords || [],
        k =>
          _.includes(event.preview.toLowerCase(), k.toLowerCase()) ||
          (event.payload && _.includes(event.payload.text.toLowerCase(), k.toLowerCase()))
      )
    )
  }

  if (choice) {
    temp['skill-choice-valid'] = true
    temp['skill-choice-ret'] = choice
  } else {<commit_msg>fix(single_choice): parse answer with nlu<commit_after>'use strict'
const _ = require('lodash')
const INTENT_PREFIX = 'intent:'

/**
 * Get a variable under this user's storage
 * @title Validate user choice
 * @category Skills
 * @hidden true
 * @author Botpress, Inc.
 * @param {string} data - The parameters of the available choices
 */
const validateChoice = async data => {
  let choice = undefined
  const config = await bp.config.getModuleConfigForBot('basic-skills', event.botId)
  const nb = _.get(event.preview.match(/^[#).!]?([\d]{1,2})[#).!]?$/), '[1]')

  if (config.matchNumbers && nb) {
    const index = parseInt(nb) - 1
    const element = await bp.cms.getContentElement(event.botId, data.contentId)
    choice = _.get(element, `formData.choices.${index}.value`)
  }

  if (!choice && config.matchNLU) {
    choice = _.findKey(data.keywords, keywords => {
      const intents = keywords
        .filter(x => x.toLowerCase().startsWith(INTENT_PREFIX))
        .map(x => x.substr(INTENT_PREFIX.length))
      return _.some(intents, k => event.nlu.intent.name === k)
    })
  }

  if (!choice) {
    choice = _.findKey(data.keywords, keywords =>
      _.some(
        keywords || [],
        k =>
          _.includes(event.preview.toLowerCase(), k.toLowerCase()) ||
          (event.payload && _.includes(event.payload.text.toLowerCase(), k.toLowerCase()))
      )
    )
  }

  if (choice) {
    temp['skill-choice-valid'] = true
    temp['skill-choice-ret'] = choice
  } else {
{'fraction_non_alphanumeric': 0.1685505319148936, 'fraction_numerical': 0.0026595744680851063, 'mean_word_length': 3.144628099173554, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, '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': '673549', 'n_tokens_mistral': 977, 'n_tokens_neox': 974, 'n_words': 213}