From facd8d912ffec8e804a004fb4cb6de8a58ea3cdb Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Fri, 1 Jan 2021 15:58:29 +0530 Subject: [PATCH] Integrate telegram with accident plugin --- src/plugins/Accident.js | 10 ++++++++++ src/sample.config.js | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/plugins/Accident.js b/src/plugins/Accident.js index a0aab44..93808e4 100644 --- a/src/plugins/Accident.js +++ b/src/plugins/Accident.js @@ -3,7 +3,17 @@ import PropTypes from "prop-types"; import { Box, Button, Heading, Text } from "grommet"; import { Aid, Impact } from "grommet-icons"; +import Telegram from "../utils/telegram"; +import { TG_API, TG_USERID } from "../config"; + function sendNotification(close) { + const bot = new Telegram(TG_API); + bot.sendMessage(TG_USERID, "User detected in an accident. Location has been attached below."); + navigator.geolocation.getCurrentPosition( + position => bot.sendLocation( TG_USERID, + position.coords.latitude, position.coords.longitude), + () => bot.sendMessage(TG_USERID, "Error retrieving location") + ); setTimeout(close, 2000); } diff --git a/src/sample.config.js b/src/sample.config.js index cf5d589..12a0c13 100644 --- a/src/sample.config.js +++ b/src/sample.config.js @@ -1,3 +1,5 @@ const WS_BASE = "http://localhost:5050/"; +const TG_API = "xxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxx"; +const TG_USERID = 123456789; -export { WS_BASE }; +export { WS_BASE, TG_API, TG_USERID };