Skip to content

Commit a5b86f3

Browse files
committed
Allowed to send location: #853
1 parent 7092f72 commit a5b86f3

4 files changed

Lines changed: 58 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Use telegram service to communicate with ioBroker
3838
### **WORK IN PROGRESS**
3939
-->
4040
### **WORK IN PROGRESS**
41+
- (@GermanBluefox) A received location or venue is now written to the new state `communicate.requestLocation` as `latitude;longitude` (role `value.gps`), so it can be shown e.g. on a map
4142
- (@GermanBluefox) Fixed: recipients can now be mixed by username and first name in one list - a recipient without a public telegram username is matched by first name even when "store username" is active
4243
- (@GermanBluefox) Added the missing translations for the configuration labels (API URL, port, certificates, media quality, ...) in all languages
4344
- (@GermanBluefox) Robustness: all telegram API calls now catch their errors, so a failing call can no longer terminate the adapter with an unhandled promise rejection

docs/en/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,18 @@ sendTo('telegram.0', 'send', {
313313
});
314314
```
315315

316+
## Receiving a location
317+
When a user shares a location with the bot (paperclip → location) or sends a venue, the coordinates are written to the state `telegram.INSTANCE.communicate.requestLocation` as a `latitude;longitude` string (role `value.gps`). The metadata states (`requestChatId`, `requestMessageId`, `requestUserId`) are updated as well, so you know who sent it.
318+
319+
```javascript
320+
on({ id: 'telegram.0.communicate.requestLocation', change: 'any' }, obj => {
321+
const [latitude, longitude] = obj.state.val.split(';').map(parseFloat);
322+
const user = getState('telegram.0.communicate.requestUserId').val;
323+
console.log(`User ${user} is at ${latitude}, ${longitude}`);
324+
// e.g. forward the coordinates to a map widget
325+
});
326+
```
327+
316328
## Updating messages
317329
The following methods allow you to change an existing message in the message history instead of sending a new one with a result of an action. This is most useful for messages with *inline keyboards* using callback queries, but can also help reduce clutter in conversations with regular chat bots.
318330

io-package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,30 @@
612612
},
613613
"native": {}
614614
},
615+
{
616+
"_id": "communicate.requestLocation",
617+
"type": "state",
618+
"common": {
619+
"name": {
620+
"en": "GPS location of last received request (latitude;longitude)",
621+
"de": "GPS-Position der letzten empfangenen Anfrage (Breite;Länge)",
622+
"ru": "GPS-координаты последнего полученного запроса (широта;долгота)",
623+
"pt": "Localização GPS do último pedido recebido (latitude;longitude)",
624+
"nl": "GPS-locatie van het laatste ontvangen verzoek (breedtegraad;lengtegraad)",
625+
"fr": "Position GPS de la dernière demande reçue (latitude;longitude)",
626+
"it": "Posizione GPS dell'ultima richiesta ricevuta (latitudine;longitudine)",
627+
"es": "Ubicación GPS de la última solicitud recibida (latitud;longitud)",
628+
"pl": "Lokalizacja GPS ostatniego otrzymanego żądania (szerokość;długość)",
629+
"uk": "GPS-координати останнього отриманого запиту (широта;довгота)",
630+
"zh-cn": "最后收到请求的 GPS 位置(纬度;经度)"
631+
},
632+
"type": "string",
633+
"role": "value.gps",
634+
"read": true,
635+
"write": false
636+
},
637+
"native": {}
638+
},
615639
{
616640
"_id": "communicate.response",
617641
"type": "state",

src/main.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1501,7 +1501,16 @@ class Telegram extends Adapter {
15011501
// by `processTelegramText` (which is bound via `bot.onText`). As a result the request metadata
15021502
// (chat id, message id, user id) would stay empty for received files. Populate it here so the
15031503
// sender can be identified. See https://github.com/iobroker-community-adapters/ioBroker.telegram/issues/1043
1504-
if (msg.voice || msg.photo || msg.video || msg.video_note || msg.audio || msg.document) {
1504+
if (
1505+
msg.voice ||
1506+
msg.photo ||
1507+
msg.video ||
1508+
msg.video_note ||
1509+
msg.audio ||
1510+
msg.document ||
1511+
msg.location ||
1512+
msg.venue
1513+
) {
15051514
this.setState('communicate.requestChatId', { val: msg.chat.id, ack: true });
15061515
this.setState('communicate.requestMessageId', { val: msg.message_id, ack: true });
15071516
this.setState('communicate.requestMessageThreadId', {
@@ -1513,6 +1522,17 @@ class Telegram extends Adapter {
15131522
}
15141523
}
15151524

1525+
// A shared location (paperclip -> location) or a venue (location + title/address) carries a
1526+
// latitude/longitude. Expose it as a "latitude;longitude" GPS string so it can be shown e.g. on a
1527+
// vis/jarvis map. See https://github.com/iobroker-community-adapters/ioBroker.telegram/issues/853
1528+
const location = msg.venue?.location || msg.location;
1529+
if (location) {
1530+
this.setState('communicate.requestLocation', {
1531+
val: `${location.latitude};${location.longitude}`,
1532+
ack: true,
1533+
});
1534+
}
1535+
15161536
if (msg.voice) {
15171537
try {
15181538
this.saveFile(

0 commit comments

Comments
 (0)