-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInboundWebhookHandler.ts
More file actions
45 lines (37 loc) · 1.18 KB
/
InboundWebhookHandler.ts
File metadata and controls
45 lines (37 loc) · 1.18 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
import { APIGatewayProxyEvent } from "aws-lambda";
import { GitHubStatusUpdater } from "./GitHubStatusUpdater";
export default class InboundWebhookHandler {
protected event: APIGatewayProxyEvent;
protected body: any;
constructor (event: APIGatewayProxyEvent) {
this.event = event;
this.body = JSON.parse(event.body);
}
protected isUserAuthed(): boolean {
return this.body.authed_users.includes(this.body.event.user.id);
}
protected getAccessToken(): string {
return '';
}
async handle () {
if (! this.isUserAuthed()) {
return {
statusCode: 204,
body: 'User not subscribed'
};
}
const accessToken = this.getAccessToken();
const updater = new GitHubStatusUpdater(accessToken);
await updater.updateStatus(
this.body.event.user.profile.status_emoji,
this.body.event.user.profile.status_text,
false
);
return {
statusCode: 200,
body: JSON.stringify({
message: 'Status updated for ' + this.body.event.user.real_name,
})
}
}
}