-
-
Notifications
You must be signed in to change notification settings - Fork 310
/
AlexaHandles.ts
109 lines (96 loc) 路 3.33 KB
/
AlexaHandles.ts
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { EnumLike, HandleOptions, InputType, Jovo } from '@jovotech/framework';
import { AlexaRequest } from './AlexaRequest';
import { PermissionStatus, PurchaseResultLike } from './interfaces';
export type PermissionType = 'timers' | 'reminders';
export enum IspType {
Upsell = 'Upsell',
Buy = 'Buy',
Cancel = 'Cancel',
}
export enum AudioPlayerType {
PlaybackStarted = 'AudioPlayer.PlaybackStarted',
PlaybackNearlyFinished = 'AudioPlayer.PlaybackNearlyFinished',
PlaybackFinished = 'AudioPlayer.PlaybackFinished',
PlaybackStopped = 'AudioPlayer.PlaybackStopped',
PlaybackFailed = 'AudioPlayer.PlaybackFailed',
}
export enum PlaybackControllerType {
NextCommandIssued = 'PlaybackController.NextCommandIssued',
PreviousCommandIssued = 'PlaybackController.PreviousCommandIssued',
PlayCommandIssued = 'PlaybackController.PlayCommandIssued',
PauseCommandIssued = 'PlaybackController.PauseCommandIssued',
}
export type IspTypeLike = EnumLike<IspType> | string;
export type AudioPlayerTypeLike = EnumLike<AudioPlayerType> | string;
export type PlaybackControllerTypeLike = EnumLike<PlaybackControllerType> | string;
export class AlexaHandles {
static onPermission(status: PermissionStatus, type?: PermissionType): HandleOptions {
return {
global: true,
types: ['Connections.Response'],
platforms: ['alexa'],
if: (jovo: Jovo) =>
(jovo.$request as AlexaRequest).request?.name === 'AskFor' &&
(jovo.$request as AlexaRequest).request?.payload?.status === status &&
(type
? (jovo.$request as AlexaRequest).request?.payload?.permissionScope ===
`alexa::alerts:${type}:skill:readwrite`
: true),
};
}
static onIsp(type: IspTypeLike, purchaseResult?: PurchaseResultLike): HandleOptions {
return {
global: true,
types: ['Connections.Response'],
platforms: ['alexa'],
if: (jovo: Jovo) => {
const result = purchaseResult
? (jovo.$request as AlexaRequest).request?.payload?.purchaseResult === purchaseResult
: true;
return (jovo.$request as AlexaRequest).request?.name === type && result;
},
};
}
static onDialogApiInvoked(name?: string): HandleOptions {
return {
global: true,
types: ['Dialog.API.Invoked'],
platforms: ['alexa'],
if: (jovo: Jovo) =>
name ? (jovo.$request as AlexaRequest).request?.apiRequest?.name === name : true,
};
}
static onAudioPlayer(type: AudioPlayerTypeLike): HandleOptions {
return {
global: true,
types: [type],
platforms: ['alexa'],
};
}
static onPlaybackController(type: PlaybackControllerTypeLike): HandleOptions {
return {
global: true,
types: [type],
platforms: ['alexa'],
};
}
static onCanFulfillIntentRequest(): HandleOptions {
return {
global: true,
types: ['CanFulfillIntentRequest'],
platforms: ['alexa'],
};
}
static onTask(taskName: string, taskVersion?: number | string): HandleOptions {
return {
types: [InputType.Launch],
if: (jovo: Jovo) => {
const task = jovo.$alexa?.task.getTask();
if (!task) return false;
if (!jovo.$alexa?.task.hasTaskName(taskName)) return false;
if (taskVersion && !jovo.$alexa.task.isVersion(taskVersion)) return false;
return true;
},
};
}
}