Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: capture block #51

Merged
merged 3 commits into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { HandlerFactory } from '@voiceflow/client';

import { T } from '@/lib/constants';
import CommandHandler from '@/lib/services/voiceflow/handlers/command';
import { IntentRequest, RequestType } from '@/lib/services/voiceflow/types';
import { addRepromptIfExists } from '@/lib/services/voiceflow/utils';

import { IntentRequest, RequestType } from '../../types';
import { addRepromptIfExists } from '../../utils';
import CommandHandler from '../command';
import getBestScore from './score';

type Choice = {
Expand Down
2 changes: 1 addition & 1 deletion lib/services/test/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { CodeHandler, EndHandler, FlowHandler, IfHandler, IntegrationsHandler, R
import AccountLinkingHandler from '@/lib/services/voiceflow/handlers/accountLinking';
import CaptureHandler from '@/lib/services/voiceflow/handlers/capture';
import CardHandler from '@/lib/services/voiceflow/handlers/card';
import ChoiceHandler from '@/lib/services/voiceflow/handlers/choice';
import InteractionHandler from '@/lib/services/voiceflow/handlers/interaction';
import PermissionCardHandler from '@/lib/services/voiceflow/handlers/permissionCard';
import ResetHandler from '@/lib/services/voiceflow/handlers/reset';
Expand All @@ -13,6 +12,7 @@ import StreamHandler from '@/lib/services/voiceflow/handlers/stream';
import { Config } from '@/types';

import CancelPaymentHandler from './cancelPayment';
import ChoiceHandler from './choice';
import DisplayHandler from './display';
import PaymentHandler from './payment';
import ReminderHandler from './reminder';
Expand Down
11 changes: 6 additions & 5 deletions lib/services/voiceflow/handlers/capture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,17 @@ export const CaptureHandler: HandlerFactory<Capture, typeof utilsObj> = (utils)
return utils.commandHandler.handle(context, variables);
}

const { intent } = request.payload;
// "input" is only passed through the prototype tool
const { intent, input } = request.payload;

// try to match the first slot of the intent to the variable
const input = _.keys(intent.slots).length === 1 ? _.values(intent.slots)[0]?.value : null;
const value = (_.keys(intent.slots).length === 1 && _.values(intent.slots)[0]?.value) || input;

if (input) {
const num = utils.wordsToNumbers(input);
if (value) {
const num = utils.wordsToNumbers(value);

if (typeof num !== 'number' || Number.isNaN(num)) {
variables.set(block.variable, input);
variables.set(block.variable, value);
} else {
variables.set(block.variable, num);
}
Expand Down
2 changes: 0 additions & 2 deletions lib/services/voiceflow/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import AccountLinkingHandler, { AccountLinkingResponseBuilder } from './accountL
import CancelPaymentHandler, { CancelPaymentResponseBuilder } from './cancelPayment';
import CaptureHandler from './capture';
import CardHandler, { CardResponseBuilder } from './card';
import ChoiceHandler from './choice';
import DisplayHandler, { DisplayResponseBuilder } from './display';
import InteractionHandler from './interaction';
import PaymentHandler, { PaymentResponseBuilder } from './payment';
Expand Down Expand Up @@ -43,7 +42,6 @@ export default ({ API_HANDLER_ENDPOINT, INTEGRATIONS_HANDLER_ENDPOINT, CODE_HAND
ResetHandler(),
DisplayHandler(),
StreamHandler(),
ChoiceHandler(),
CodeHandler({ endpoint: CODE_HANDLER_ENDPOINT }),
EndHandler(),
FlowHandler(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect } from 'chai';
import sinon from 'sinon';

import { T } from '@/lib/constants';
import { ChoiceHandler } from '@/lib/services/voiceflow/handlers/choice';
import { ChoiceHandler } from '@/lib/services/test/handlers/choice';
import { RequestType } from '@/lib/services/voiceflow/types';

describe('choice handler unit tests', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';

import getBestScore, { Choice } from '@/lib/services/voiceflow/handlers/choice/score';
import getBestScore, { Choice } from '@/lib/services/test/handlers/choice/score';

describe('score utils', () => {
describe('getBestScore', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/services/test/handlers/display.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Test displayHandler unit tests', () => {
const block = { nextId: 'next-id' };
const context = { trace: { debug: sinon.stub() } };
expect(displayHandler.handle(block as any, context as any, null as any, null as any)).to.eql(block.nextId);
expect(context.trace.debug.args).to.eql([['__display__ - entered'], ['__display__ - redirecting to the next block']]);
expect(context.trace.debug.args).to.eql([['__display__ - entered'], ['__display__ - redirecting to the next step']]);
});
});
});
5 changes: 1 addition & 4 deletions tests/lib/services/test/handlers/payment.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ describe('Test paymentHandler unit tests', () => {
const block = { fail_id: 'fail-id' };
const context = { trace: { debug: sinon.stub() } };
expect(paymentHandler.handle(block as any, context as any, null as any, null as any)).to.eql(block.fail_id);
expect(context.trace.debug.args).to.eql([
['__payment__ - entered'],
['__payment__ - success link is not provided, redirecting to the fail block'],
]);
expect(context.trace.debug.args).to.eql([['__payment__ - entered'], ['__payment__ - success path not provided, redirecting to the fail path']]);
});
});
});
2 changes: 1 addition & 1 deletion tests/lib/services/test/handlers/reminder.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Test reminderHandler unit tests', () => {
expect(reminderHandler.handle(block as any, context as any, null as any, null as any)).to.eql(block.fail_id);
expect(context.trace.debug.args).to.eql([
['__reminder__ - entered'],
['__reminder__ - success link is not provided, redirecting to the fail block'],
['__reminder__ - success path not provided, redirecting to the fail path'],
]);
});
});
Expand Down