-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
types.ts
146 lines (119 loc) · 3.37 KB
/
types.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { NotificationsCategory } from '../types';
import { AWSPinpointProviderConfig } from './Providers/AWSPinpointProvider/types';
export type NotificationsSubcategory = 'InAppMessaging';
export type UserInfo = {
attributes?: Record<string, string[]>;
demographic?: {
appVersion?: string;
locale?: string;
make?: string;
model?: string;
modelVersion?: string;
platform?: string;
platformVersion?: string;
timezone?: string;
};
location?: {
city?: string;
country?: string;
latitude?: number;
longitude?: number;
postalCode?: string;
region?: string;
};
metrics?: Record<string, number>;
};
export type InAppMessagingEvent = {
name: string;
attributes?: Record<string, string>;
metrics?: Record<string, number>;
};
export interface InAppMessagingConfig {
listenForAnalyticsEvents?: boolean;
AWSPinpoint?: AWSPinpointProviderConfig;
}
export interface InAppMessagingProvider {
// you need to implement these methods
// configure your provider
configure(config: object): object;
// return category ('Notifications')
getCategory(): NotificationsCategory;
// return sub-category ('InAppMessaging')
getSubCategory(): NotificationsSubcategory;
// return the name of you provider
getProviderName(): string;
// get in-app messages from provider
getInAppMessages(): Promise<any>;
// filters in-app messages based on event input and provider logic
processInAppMessages(
messages: InAppMessage[],
event: InAppMessagingEvent
): Promise<InAppMessage[]>;
// identify the current user with the provider
identifyUser(userId: string, userInfo: UserInfo): Promise<void>;
}
export type InAppMessageLayout =
| 'BOTTOM_BANNER'
| 'CAROUSEL'
| 'FULL_SCREEN'
| 'MIDDLE_BANNER'
| 'MODAL'
| 'TOP_BANNER';
export type InAppMessageAction = 'CLOSE' | 'DEEP_LINK' | 'LINK';
export type InAppMessageTextAlign = 'center' | 'left' | 'right';
interface InAppMessageContainer {
style?: InAppMessageStyle;
}
interface InAppMessageHeader {
content: string;
style?: InAppMessageStyle;
}
interface InAppMessageBody {
content: string;
style?: InAppMessageStyle;
}
export interface InAppMessageImage {
src: string;
}
export interface InAppMessageButton {
title: string;
action: InAppMessageAction;
url?: string;
style?: InAppMessageStyle;
}
export interface InAppMessageStyle {
backgroundColor?: string;
borderRadius?: number;
color?: string;
textAlign?: InAppMessageTextAlign;
}
export interface InAppMessageContent {
container?: InAppMessageContainer;
header?: InAppMessageHeader;
body?: InAppMessageBody;
image?: InAppMessageImage;
primaryButton?: InAppMessageButton;
secondaryButton?: InAppMessageButton;
}
export interface InAppMessage {
id: string;
layout: InAppMessageLayout;
content: InAppMessageContent[];
metadata?: any;
}
export type OnMessageInteractionEventHandler = (message: InAppMessage) => any;
export interface OnMessageInteractionEventListener {
handleEvent: OnMessageInteractionEventHandler;
remove: () => void;
}
export enum InAppMessageInteractionEvent {
MESSAGE_RECEIVED = 'MESSAGE_RECEIVED_EVENT',
MESSAGE_DISPLAYED = 'MESSAGE_DISPLAYED_EVENT',
MESSAGE_DISMISSED = 'MESSAGE_DISMISSED_EVENT',
MESSAGE_ACTION_TAKEN = 'MESSAGE_ACTION_TAKEN_EVENT',
}
export type InAppMessageConflictHandler = (
messages: InAppMessage[]
) => InAppMessage;