twilio-ccai-fulfillment-tools
Version:
A collection of tools to assist in the creation of Twilio CCAI Integration cards via fulfillment scripts
23 lines (20 loc) • 775 B
text/typescript
import { TMapContext } from '..';
import { GoogleCloudDialogflowV2WebhookRequest } from 'actions-on-google';
import { WebhookClient } from 'dialogflow-fulfillment';
import { addIntentsToMapContext } from './addIntentsToMapContext';
export const createMapHandler = (
createContext: () => TMapContext | undefined,
dfRequest: GoogleCloudDialogflowV2WebhookRequest,
withIntentDetailsAdded = true
) => (agent: WebhookClient): void => {
if (dfRequest.queryResult?.fulfillmentText) {
agent.add(dfRequest.queryResult.fulfillmentText);
}
const mapContext = createContext();
if (mapContext) {
if (withIntentDetailsAdded) {
addIntentsToMapContext(mapContext, dfRequest);
}
agent.setContext(mapContext);
}
};