<commit_before>/**
 * Update user language
 * @title Update user language
 * @category Language
 * @author Botpress, Inc.
 * @param {string} lang - The language code, e.g. "en"
 */
const switchLanguage = async language => {
  event.state.user.language = language
  bp.realtime.sendPayload(bp.RealTimePayload.forVisitor(event.target, 'webchat.data', { payload: { language } }))
  await event.setFlag(bp.IO.WellKnownFlags.FORCE_PERSIST_STATE, true)
}

return switchLanguage(args.lang)<commit_msg>fix(channel-web): fix switching user language (#5753)<commit_after>async function getVisitorId(userId) {
  const rows = await bp.database('web_user_map').where({ userId })
  if (rows && rows.length) {
    return rows[0] && rows[0].visitorId
  }
}

/**
 * Update user language
 * @title Update user language
 * @category Language
 * @author Botpress, Inc.
 * @param {string} lang - The language code, e.g. "en"
 */
const switchLanguage = async language => {
  event.state.user.language = language
  const visitorId = await getVisitorId(event.target)
  bp.realtime.sendPayload(bp.RealTimePayload.forVisitor(visitorId, 'webchat.data', { payload: { language } }))
  await event.setFlag(bp.IO.WellKnownFlags.FORCE_PERSIST_STATE, true)
}

return switchLanguage(args.lang)
{'fraction_non_alphanumeric': 0.13423351866560762, 'fraction_numerical': 0.004765687053216839, 'mean_word_length': 4.7534246575342465, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5002894', 'n_tokens_mistral': 405, 'n_tokens_neox': 398, 'n_words': 93}