<commit_before>import { DetectIntentResponse } from 'dialogflow'
import { MARKET_INFO_INTENT, SPOT_QUOTE_INTENT, TRADES_INFO_INTENT } from './intents'
import { PlatformAdapter } from 'rt-platforms'
import { showBlotter, showCurrencyPair, showMarket } from './intent-handlers'
import { getCurrency, getCurrencyPair, getIntentDisplayName, getNumber } from './intentUtils'
import { BlotterFilters } from '../MainRoute/widgets/blotter'

export const handleIntent = (response: DetectIntentResponse, platformAdapter: PlatformAdapter) => {
  const queryResult = response.queryResult
  const intentDisplayName = getIntentDisplayName(queryResult)
  switch (intentDisplayName) {
    case SPOT_QUOTE_INTENT: {
      const currencyPair = getCurrencyPair(queryResult)
      if (!currencyPair) {
        console.error(`No currency pair in queryResult`)
        return
      }
      showCurrencyPair(currencyPair, platformAdapter)
      return
    }
    case MARKET_INFO_INTENT:
      showMarket(platformAdapter)
      return
    case TRADES_INFO_INTENT: {
      const currencyPair = getCurrencyPair(queryResult)
      const currency = getCurrency(queryResult)
      const filters: BlotterFilters = {
        dealtCurrency: [currency],
        symbol: [currencyPair],
        count: getNumber(response.queryResult),
      }
      showBlotter(filters, platformAdapter)
      return
    }
    default:
      console.log(`Do not know how to handle intent ${intentDisplayName}`)
  }
}<commit_msg>refactor handling intent<commit_after>import { DetectIntentResponse } from 'dialogflow'
import { MARKET_INFO_INTENT, SPOT_QUOTE_INTENT, TRADES_INFO_INTENT } from './intents'
import { PlatformAdapter } from 'rt-platforms'
import { showBlotter, showCurrencyPair, showMarket } from './intent-handlers'
import { getCurrency, getCurrencyPair, getIntentDisplayName, getNumber } from './intentUtils'
import { BlotterFilters } from '../MainRoute/widgets/blotter'

export const handleIntent = (response: DetectIntentResponse, platformAdapter: PlatformAdapter) => {
  const queryResult = response.queryResult
  const intentDisplayName = getIntentDisplayName(queryResult)
  switch (intentDisplayName) {
    case SPOT_QUOTE_INTENT: {
      const currencyPair = getCurrencyPair(queryResult)
      if (!currencyPair) {
        console.error(`No currency pair in queryResult`)
        return
      }
      showCurrencyPair(currencyPair, platformAdapter)
      return
    }
    case MARKET_INFO_INTENT:
      showMarket(platformAdapter)
      return
    case TRADES_INFO_INTENT: {
      const currencyPair = getCurrencyPair(queryResult)
      const currency = getCurrency(queryResult)
      const filters: BlotterFilters = {
        dealtCurrency: [currency],
        symbol: [currencyPair],
        count: getNumber(queryResult),
      }
      showBlotter(filters, platformAdapter)
      return
    }
    default:
      console.log(`Do not know how to handle intent ${intentDisplayName}`)
  }
}
{'fraction_non_alphanumeric': 0.08491204330175914, 'fraction_numerical': 0.0, 'mean_word_length': 3.9119601328903655, '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': '1685981', 'n_tokens_mistral': 828, 'n_tokens_neox': 830, 'n_words': 192}