Compare commits
	
		
			2 Commits
		
	
	
		
			ace77028c4
			...
			facd8d912f
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| facd8d912f | |||
| b743cbc9a5 | 
@@ -7,6 +7,7 @@
 | 
			
		||||
    "@testing-library/jest-dom": "^4.2.4",
 | 
			
		||||
    "@testing-library/react": "^9.3.2",
 | 
			
		||||
    "@testing-library/user-event": "^7.1.2",
 | 
			
		||||
    "axios": "^0.21.1",
 | 
			
		||||
    "grommet": "^2.16.2",
 | 
			
		||||
    "grommet-icons": "^4.5.0",
 | 
			
		||||
    "polished": "^4.0.5",
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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 };
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										0
									
								
								src/utils/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								src/utils/index.js
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										19
									
								
								src/utils/telegram.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								src/utils/telegram.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
			
		||||
import axios from "axios";
 | 
			
		||||
 | 
			
		||||
class Telegram {
 | 
			
		||||
	constructor(token) {
 | 
			
		||||
		this.axios = axios.create({
 | 
			
		||||
			baseURL: `https://api.telegram.org/bot${token}`
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	sendMessage(chat_id, text) {
 | 
			
		||||
		this.axios.post("/sendMessage", {chat_id, text});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	sendLocation(chat_id, latitude, longitude) {
 | 
			
		||||
		this.axios.post("/sendLocation", {chat_id, latitude, longitude});
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default Telegram;
 | 
			
		||||
@@ -2590,6 +2590,13 @@ axe-core@^4.0.2:
 | 
			
		||||
  resolved "https://registry.npmjs.org/axe-core/-/axe-core-4.1.1.tgz#70a7855888e287f7add66002211a423937063eaf"
 | 
			
		||||
  integrity sha512-5Kgy8Cz6LPC9DJcNb3yjAXTu3XihQgEdnIg50c//zOC/MyLP0Clg+Y8Sh9ZjjnvBrDZU4DgXS9C3T9r4/scGZQ==
 | 
			
		||||
 | 
			
		||||
axios@^0.21.1:
 | 
			
		||||
  version "0.21.1"
 | 
			
		||||
  resolved "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8"
 | 
			
		||||
  integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==
 | 
			
		||||
  dependencies:
 | 
			
		||||
    follow-redirects "^1.10.0"
 | 
			
		||||
 | 
			
		||||
axobject-query@^2.2.0:
 | 
			
		||||
  version "2.2.0"
 | 
			
		||||
  resolved "https://registry.npmjs.org/axobject-query/-/axobject-query-2.2.0.tgz#943d47e10c0b704aa42275e20edf3722648989be"
 | 
			
		||||
@@ -5204,7 +5211,7 @@ flush-write-stream@^1.0.0:
 | 
			
		||||
    inherits "^2.0.3"
 | 
			
		||||
    readable-stream "^2.3.6"
 | 
			
		||||
 | 
			
		||||
follow-redirects@^1.0.0:
 | 
			
		||||
follow-redirects@^1.0.0, follow-redirects@^1.10.0:
 | 
			
		||||
  version "1.13.1"
 | 
			
		||||
  resolved "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.1.tgz#5f69b813376cee4fd0474a3aba835df04ab763b7"
 | 
			
		||||
  integrity sha512-SSG5xmZh1mkPGyKzjZP8zLjltIfpW32Y5QpdNJyjcfGxK3qo3NDDkZOZSFiGn1A6SclQxY9GzEwAHQ3dmYRWpg==
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user