import { Store } from 'redux' ; import { Activity } from 'botbuilder' ; import { WolfState , OutputMessageItem , OutputMessageType } from '../types' ; import { getOutputMessageQueue } from '../selectors' ; import { clearMessageQueue } from '../actions' ; const logState = require ( 'debug' ) ( 'wolf:s5:enterState' ) ; const log = require ( 'debug' ) ( 'wolf:s5' ) ; export interface OuttakeResult { messageStringArray : string [ ] ; messageItemArray : OutputMessageItem [ ] ; messageActivityArray : Partial < Activity > [ ] ; } param store export default function outtake ( store ) { const { dispatch , getState } = store ; const messageQueue = getOutputMessageQueue ( getState ( ) ) ; logState ( getState ( ) ) ; const slotFillMessage = createMessage ( messageQueue , OutputMessageType . slotFillMessage ) ; const abilityCompleteMessage = createMessage ( messageQueue , OutputMessageType . abilityCompleteMessage ) ; const validateMessage = createMessage ( messageQueue , OutputMessageType . validateReason ) ; const retryMessage = createMessage ( messageQueue , OutputMessageType . retryMessage ) ; const queryMessage = createMessage ( messageQueue , OutputMessageType . queryMessage ) ; const nextAbilityMessage = createMessage ( messageQueue , OutputMessageType . nextAbilityMessage ) ; const messageStringArray = [ slotFillMessage , abilityCompleteMessage , nextAbilityMessage , validateMessage , retryMessage , queryMessage ] . filter ( ( message ) => message ) ; const messageItemArray = messageQueue ; dispatch ( clearMessageQueue ( ) ) ; const messageActivityArray = messageStringArray . map ( ( msg ) => ( { type : 'message' , text : msg } ) ) ; return { messageStringArray , messageItemArray , messageActivityArray } ; } /**
 * Create a single string from grouped messageTypes
 */ const createMessage = ( messageQueue , messageType ) => { const queue = messageQueue . filter ( ( item ) => item . type === messageType ) . filter ( ( item ) => item . message ) ; const messages = `${ queue . map ( ( _ ) => _ . message ) . join ( ', ' ) }` ; return messages ; } ;