Skip to content

Commit

Permalink
Refactor voice compass methods
Browse files Browse the repository at this point in the history
  • Loading branch information
peterszerzo committed Feb 21, 2024
1 parent dcbd6cf commit eb5d7d0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
12 changes: 8 additions & 4 deletions packages/voice-compass/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export type Context = Record<string, any>;

// The journey manager object
export interface VoiceCompass {
sendStep: (data: StepData) => Promise<StepUpdate>;
sendStep: (stepId: string, context?: Context) => Promise<StepUpdate>;
changeJourneyId: (journeyId: string) => void;
getLastUpdate: () => Update | null;
getLastStep: () => Update | null;
}

export interface Update {
Expand Down Expand Up @@ -114,7 +114,11 @@ export const create = (config: Config): VoiceCompass => {
});
};

const sendStep = (stepData: StepData) => {
const sendStep = (stepId: string, context?: Context) => {
const stepData: StepData = {
stepId,
context,
};
if (stepData.stepId === lastUpdate?.stepId && config.preventRepeats) {
const warning = `Duplicate step ID detected, step update prevented: ${stepData.stepId}`;
if (config.debug) {
Expand All @@ -140,7 +144,7 @@ export const create = (config: Config): VoiceCompass => {
currentJourneyId = newJourneyId;
saveSession();
},
getLastUpdate: () => {
getLastStep: () => {
return lastUpdate;
},
};
Expand Down
6 changes: 3 additions & 3 deletions packages/website/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export const version = "0.0.14";

export const umdScriptTags = {
chatCore: `https://unpkg.com/@nlxai/chat-core@${version}/lib/index.umd.js`,
chatWidget: `https://unpkg.com/@nlxai/chat-widget@${version}/lib/index.umd.js`,
voiceCompass: `https://unpkg.com/@nlxai/voice-compass@${version}/lib/index.umd.js`,
chatCore: `https://unpkg.com/@nlxai/chat-core/lib/index.umd.js`,
chatWidget: `https://unpkg.com/@nlxai/chat-widget/lib/index.umd.js`,
voiceCompass: `https://unpkg.com/@nlxai/voice-compass/lib/index.umd.js`,
};

export const packageUrls = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ The starting point of the package is the \`create\` method, which initializes a
The resulting client has the following methods:
- \`sendStep\`, sending a step update with the following fields:
- \`sendStep\`, sending a step update with the following arguments:
- \`stepId\`: the next step to transition to.
- \`context\` (optional, advanced): set Dialog Studio context attributes.
- \`changeJourneyId\` (advanced): transition to a new journey.
- \`getLatestStepId\` (advanced): retrieve the ID of the last step played.
- \`getLastStep\` (advanced): retrieve the step ID, journey ID and context of the last step, in a single object.
`;

export const MultimodalApiReference = () => {
Expand Down
4 changes: 1 addition & 3 deletions packages/website/src/snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,7 @@ const voiceCompassCommonScript = ({
languageCode: "${config?.languageCode || "REPLACE_WITH_LANGUAGE_CODE"}",
});
client.sendStep({
stepId: "${config?.testStepId || "REPLACE_WITH_STEP_ID"}",
});`;
client.sendStep("${config?.testStepId || "REPLACE_WITH_STEP_ID"}");`;

export const voiceCompassSetupSnippet = ({
config,
Expand Down

0 comments on commit eb5d7d0

Please sign in to comment.