TerraMaterBot
A Telegram Chat Bot for Earth Observation
Guest blog post by Fabio Vivian
Nowadays, smartphones are ubiquitous throughout society and highly simplify modern day communication via instant messaging or voice over IP services. Telegram is a free, cloud-based, open source (on client-side) service running on many different platforms such as Android, iOS, Windows Phone and NT, macOS and Linux. Telegram also offers chat bots and the possibility for developers to launch their own bots without much overhead.
Nowadays, smartphones are ubiquitous throughout the society and highly simplify modern day communication via instant messaging or voice over IP services. Telegram is a free, cloud-based, open source (on client-side) service running on many different platforms such as Android, iOS, Windows Phone and NT, macOS and Linux. Telegram also offers chat bots and the possibility for developers to launch their own bots.
In order to access data European Union’s Earth observation programme Copernicus, managed by the European Space Agency in collaboration with the European Commission, aims on providing a vast amount of global, continuous, high quality Earth observation data. Its remote sensing component, the Sentinel missions provide land, ocean and atmospheric monitoring. Although the data is openly available and free of charge, many people (except those working in this domain) don’t know about this tremendous amount of satellite data. This Telegram chat bot is a tool for the everyday normal smartphone user, not necessarily related to anything connected to remote sensing, to see the output of a multiannual, multibillion Satellite mission in an easy way.
Data generated by Sentinel-1, Sentinel-2, Sentinel-3 and Sentinel-5P can be accessed via the Telegram TerraMaterBot, which lets the user get an image sent to his phone with just three taps. The bot was developed in the framework of a Swiss traineeship within ESA at the European Space Research Institute (ESRIN) in Frascati, Italy. Its source code is open-source and can be found on GitHub.
In the Telegram app, for example on the phone, the user can look for @TerraMaterBot and connect to it. Once in the chat view, the conversation can be started with the command /start, which will trigger the bot to send a welcoming message. The image below shows a conversation with the bot at a later stage. The buttons (/S1, /S2, /S3, /S5P, /location and /help) are the commands which send queries to the bot and in return receive images and other information.
If the users are interested in another area rather their own location, they can use the Attachment menu in order to send an arbitrary location (and then drop a pin on the map). Even more, the user can send any location (e.g. country, city, lake, etc.) and as a response the bot sends a longitude/latitude combination in order to confirm the location; this is thanks to the Nominatim service.
Each of the commands above makes the bot call a function in the backend. Each of the /Sx commands involves a GetFeature request to Sentinel Hub’s web feature service (WFS) in order to find the latest acquisition date for a chosen location. For a WFS GetFeature request one needs several parameters, depending on the data’s source satellite. An exemplary url request might look something like this:
params = { 'service': 'WFS',
'request': 'GetFeature',
'outputformat': 'application/json',
'srs': 'EPSG%3A3857',
'maxfeatures': '100',
'typenames': 'S2.TILE',
'maxcc': 5,
'bbox': f'{xmin}, {ymin}, {xmax}, {ymax}'}url_wfs = f'https://services.sentinel-hub.com/ogc/wfs/{ID}'res_wfs = requests.get(url_wfs, {**params})
The response (res_wfs) of this simple HTTP get request will be a json with data about the location (bbox) and layer (typenames) containing information such as time, date, geometry, or product name.
The date will then be used for a GetMap WMS request with the following exemplary parameters:
params = { 'service': 'WMS',
'request': 'GetMap',
'layers': 'S2-TRUE-COLOR',
'srs': 'EPSG%3A3857',
'format': 'image/jpeg',
'version': '1.1.1',
'showlogo': 'false',
'height': 720,
'width': 1280,
'time': f'{date}/{date}',
'maxcc': 5,
'bbox': f'{xmin}, {ymin}, {xmax}, {ymax}'}url_base = f'https://services.sentinel-hub.com/ogc/wms/{ID}'url_wms = f'{url_base}?{urllib.parse.urlencode(params)}'
For performance reasons the url is not used for a get request since the the image would then be downloaded twice — by the server running the backend as well as by Telegram’s API. Fortunately, the Telegram Bot API offers a function to send an image to the user via url, i.e. the image is only downloaded once, by Telegram’s API.
The layers being used are predefined and for Sentinel-1 it is the VV-orthorectified, for Sentinel-2 and Sentinel-3 the True Color (bands 4, 3 and 2 for S2 and bands 8, 6 and 4 for S3, respectively) and for Sentinel-5P either NO2 or CO layer.
After the message with the image, the bot will send a link to the Sentinel-Hub EO Browser with the chosen location, satellite and band combination for the user to browse in an interactive web map.
A very nice functionality by the Telegram Bot API is the run_async decorator. It allows the developer to define certain functions to be executed asynchronously. In this bot it is used for requesting the image because this might take a few seconds. So while the backend is handling a request by one user, another user still can send and receive commands/messages by the bot in a concurrent manner.
Overall, it has been an interesting to see how chat bots can be used as an interface to Earth Observation data. They greatly lower the threshold to seeing data by delivering responses within seconds from multi-petabyte archives.
I would like to thank the Sinergise team, CloudFerro, and my colleagues at the European Space Agency for their support in this work.