You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
import fetch from 'node-fetch';
|
|
|
|
|
|
|
|
|
|
const headers = { 'Content-Type': 'application/json' };
|
|
|
|
|
|
|
|
|
|
export default async function send(event, place) {
|
|
|
|
|
let message;
|
|
|
|
|
try {
|
|
|
|
|
const format = (d) => {
|
|
|
|
|
return (
|
|
|
|
|
d.getFullYear() +
|
|
|
|
|
'-' +
|
|
|
|
|
('0' + (d.getMonth() + 1)).slice(-2) +
|
|
|
|
|
'-' +
|
|
|
|
|
('0' + d.getDate()).slice(-2) +
|
|
|
|
|
' ' +
|
|
|
|
|
('0' + d.getHours()).slice(-2) +
|
|
|
|
|
':' +
|
|
|
|
|
('0' + d.getMinutes()).slice(-2)
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
let newEvent = JSON.parse(event);
|
|
|
|
|
let startTime = `${format(new Date(newEvent.start * 1000))}`;
|
|
|
|
|
message = `${startTime} ${place.name}: ${newEvent.name}`;
|
|
|
|
|
await fetch(`http://localhost:8080/v2/send`, {
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
message,
|
|
|
|
|
number: '+4793478353',
|
|
|
|
|
recipients: ['+4793478353']
|
|
|
|
|
}),
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers
|
|
|
|
|
});
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
}
|
|
|
|
|
return message;
|
|
|
|
|
}
|