forked from microsoft/BotFramework-WebChat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhasFeedbackLoop.ts
More file actions
42 lines (36 loc) · 1.42 KB
/
hasFeedbackLoop.ts
File metadata and controls
42 lines (36 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { type WebChatActivity } from 'botframework-webchat-core';
import { literal, object, optional, safeParse, string, union, type InferOutput } from 'valibot';
const activityWithFeedbackLoopSchemaWithDisclaimer = object({
channelData: object({
feedbackLoop: object({
disclaimer: optional(string()),
type: literal('default')
})
})
});
const activityWithFeedbackLoopSchemaWithoutDisclaimer = object({
channelData: object({
feedbackLoop: object({
type: literal('default')
})
})
});
const feedbackLoopSchema = union([
activityWithFeedbackLoopSchemaWithDisclaimer,
activityWithFeedbackLoopSchemaWithoutDisclaimer
]);
type FeedbackActivity = WebChatActivity & InferOutput<typeof feedbackLoopSchema>;
/**
* @deprecated This helper function should only use for patching the service. After patching, should use `getDisclaimerFormReviewAction` instead.
*/
export function hasDisclaimer(
activity: WebChatActivity
): activity is WebChatActivity & InferOutput<typeof activityWithFeedbackLoopSchemaWithDisclaimer> {
return safeParse(activityWithFeedbackLoopSchemaWithDisclaimer, activity).success;
}
/**
* @deprecated This helper function should only use for patching the service. After patching, should use `isActionRequireReview` instead.
*/
export default function hasFeedbackLoop(activity: WebChatActivity): activity is FeedbackActivity {
return safeParse(feedbackLoopSchema, activity).success;
}