-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.ts
35 lines (33 loc) · 959 Bytes
/
handler.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
"use strict";
import { APIGatewayProxyHandler, APIGatewayProxyResult } from "aws-lambda";
import fetch from "node-fetch";
export const hello: APIGatewayProxyHandler = async (event, context) => {
return new Promise<APIGatewayProxyResult>((resolve, reject) =>
setTimeout(
() =>
resolve({
statusCode: 200,
body: JSON.stringify({
message: "Go Serverless v1.0! Your function executed successfully!",
input: event,
}),
}),
500
)
);
};
export const echoBot: APIGatewayProxyHandler = async (event, context) => {
const BASE_URL = `http://api.telegram.org/bot${process.env["TELEGRAM_TOKEN"]}/sendMessage`;
const body = JSON.parse(event.body!);
await fetch(
`${BASE_URL}?text=${encodeURI(body.message.text)}&chat_id=${encodeURI(
body.message.chat.id
)}`
);
return {
statusCode: 200,
body: JSON.stringify({
input: event,
}),
};
};