-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
73 lines (61 loc) · 1.8 KB
/
utils.js
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const axios = require('axios');
const BASE_URL = `https://api.telegram.org/bot${process.env.TOKEN}`;
async function getWhatUrl(value) {
// {
// "echo": "Zahnarzt",
// "query": "Zahnarzt",
// "suggests": [
// {
// "header": "Fachbereiche & Symptome",
// "list": [
// {
// "score": 998,
// "showSelect": "Zahnarzt",
// "select": "gruppe=ZA&fachgebiet=",
const { data } = await axios.get(
`https://suche.jameda-elements.de/what-dev?query=${value}&echo=${value}`
);
return data.suggests[0].list[0].select;
}
async function getWhereUrl(value) {
// {
// "echo": "Berlin",
// "suggests": [
// {
// "header": "Ort",
// "list": [
// {
// "score": 882,
// "select": "geoball=13%2E40629%2C52%2E524269%2C0%2E5&geo=52%2E524269%5F13%2E40629%5F%5F0%5FBerlin%5Fberlin%5FBerlin%5F1",
const { data } = await axios.get(
`https://suche.jameda-elements.de/where-dev?query=${value}&echo=${value}`
);
return data.suggests[0].list[0].select;
}
async function getSuggestions(what, where) {
const whatUrl = await getWhatUrl(what);
const whereUrl = await getWhereUrl(where);
const url = `https://jameda.de/arztsuche/?new_search=1&${whatUrl}&${whereUrl}&output=json&version=5.0.0`;
console.log({ whatUrl, whereUrl, url });
const {
data: { results }
} = await axios.get(url);
return results
.slice(0, 5)
.map(
({ name_nice, plz, ort, gesamt_note, tel }) =>
`*${name_nice}* in ${plz} ${ort} _(Note ${gesamt_note})_: [${tel}]`
);
}
function sendReply(text, chat_id) {
const url = `${BASE_URL}/sendMessage`;
return axios.post(url, {
chat_id,
text,
parse_mode: 'markdown'
});
}
module.exports = {
getSuggestions,
sendReply
};