-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.ts
More file actions
53 lines (45 loc) · 1.49 KB
/
example.ts
File metadata and controls
53 lines (45 loc) · 1.49 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
43
44
45
46
47
48
49
50
51
52
53
import GmailService from "./lib";
const serviceCredentials = {
id: 'XXXX.apps.googleusercontent.com',
secret: 'xxxxxx-xxxxx-xxx_xxxxxxxxxxxxxxxxxx',
pubsubTopic: 'Topic name',
scope: [
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/user.birthday.read',
'https://www.googleapis.com/auth/user.phonenumbers.read',
'https://www.googleapis.com/auth/contacts',
'https://mail.google.com'
].join(',')
};
const userCredentials = {
access_token: 'user access token',
refresh_token: 'user refresh token',
scope: serviceCredentials.scope
};
const pushBody = {
"message": {
"data": "base64string",
"messageId": "8080607222555870",
"message_id": "8080607222555870",
"publishTime": "2023-08-20T07:20:45.566Z",
"publish_time": "2023-08-20T07:20:45.566Z"
},
"subscription": "Subscription name"
}
const main = async () => {
const gmailService = new GmailService({
clientId: serviceCredentials.id,
clientSecret: serviceCredentials.secret,
pubSubTopic: serviceCredentials.pubsubTopic
});
gmailService.setUserCredentials(userCredentials);
const messages = await gmailService.getMessages({
pushPayload: pushBody,
userCredentials: userCredentials,
withLabel: ['INBOX'],
historyTypes: ['messageAdded']
});
console.log(messages);
}
main();