-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathemail-client.ts
151 lines (141 loc) · 4.02 KB
/
email-client.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
147
148
149
150
151
import {
ConnectClient,
ConnectClientConfig,
SubscriptionHandler,
} from "@amazon-connect/core";
import { emailNamespace } from "./email-namespace";
import { EmailRoute } from "./routes";
import { EmailContactEvents } from "./topic-keys";
import {
CreateDraftEmailContact,
DraftEmailContact,
EmailContact,
EmailContactId,
EmailThreadContact,
GetEmailThreadParams,
} from "./types";
export class EmailClient extends ConnectClient {
constructor(config?: ConnectClientConfig) {
super(emailNamespace, config);
}
/**
* Get data for an email contact
*
* @param {string} request.contactId the email contact to get data for
* @param {string} request.activeContactId the contact the agent is actively viewing
* @returns {Promise<EmailContact>} a promise that resolves to the email contact data
*/
getEmailData({
contactId,
activeContactId,
}: {
contactId: string;
activeContactId: string;
}): Promise<EmailContact> {
return this.context.proxy.request(EmailRoute.getEmailData, {
contactId,
activeContactId,
});
}
/**
* Create a draft outbound email contact.
*
* This does not send the email. This will cause {@link onDraftEmailCreated} to fire.
*
* @param {CreateDraftEmailContact} contactCreation the contact creation details
* @returns {Promise<EmailContactId>} a promise that resolves to the contact id of the draft email contact
*/
createDraftEmail(
contactCreation: CreateDraftEmailContact,
): Promise<EmailContactId> {
return this.context.proxy.request(
EmailRoute.createDraftEmail,
contactCreation,
);
}
/**
* Gets the associated email contacts with the contact association id
*
* @param {GetEmailThreadParams} getEmailThreadParams the contact association id, optional maxResults and nextToken
* @returns {Promise<{contacts: EmailThreadContact[]; nextToken?: string;}>} a promise that resolves to the associated email contacts
*/
getEmailThread(getEmailThreadParams: GetEmailThreadParams): Promise<{
contacts: EmailThreadContact[];
nextToken?: string;
}> {
return this.context.proxy.request(
EmailRoute.getEmailThread,
getEmailThreadParams,
);
}
/**
* Send the outbound email contact
*
* @param {DraftEmailContact} emailContact the email contact to send
* @returns {Promise<void>} a promise that resolves to void when the email is sent
*/
sendEmail(emailContact: DraftEmailContact): Promise<void> {
return this.context.proxy.request(EmailRoute.sendEmail, emailContact);
}
/**
* Subscribe to "The agent has accepted an inbound email contact." events.
*/
onAcceptedEmail(
handler: SubscriptionHandler<EmailContactId>,
contactId?: string,
): void {
this.context.proxy.subscribe(
{
key: EmailContactEvents.InboundContactConnected,
parameter: contactId,
},
handler,
);
}
/**
* Unsubscribe from "The agent has accepted an inbound email contact." events.
*/
offAcceptedEmail(
handler: SubscriptionHandler<EmailContactId>,
contactId?: string,
): void {
this.context.proxy.unsubscribe(
{
key: EmailContactEvents.InboundContactConnected,
parameter: contactId,
},
handler,
);
}
/**
* Subscribe to "An outbound email contact has been assigned to the agent."
* This fires for an "Agent Initiated Email Conversation"
*/
onDraftEmailCreated(
handler: SubscriptionHandler<EmailContactId>,
contactId?: string,
): void {
this.context.proxy.subscribe(
{
key: EmailContactEvents.OutboundContactConnected,
parameter: contactId,
},
handler,
);
}
/**
* Unsubscribe from "An outbound email contact has been assigned to the agent."
*/
offDraftEmailCreated(
handler: SubscriptionHandler<EmailContactId>,
contactId?: string,
): void {
this.context.proxy.unsubscribe(
{
key: EmailContactEvents.OutboundContactConnected,
parameter: contactId,
},
handler,
);
}
}