How Azure serverless helps my grandmother during Corona isolation.

Needless to say that the Corona outbreak has a serious impact on our society.  The measures that the different governments take become stricter, also in Belgium.  Yesterday, they announced that no more visitors are allowed in the retirement homes.  Understandable, because the older people are more vulnerable for the virus.  On the other hand, the loneliness that is caused by this isolation has a negative influence on their mood.  I started thinking how technology could help my grandmother to remain a bit in contact with her children, grandchildren and great-grandchildren…

Nowadays, we’re constantly taking and sharing pictures through WhatsApp.  It would be great if I could randomly display all the pictures that we share in a specific WhatsApp group on a computer screen in my grandmother’s room.  However, some challenges popped up:

  • WhatsApp doesn’t have a public API.  Only big companies get API access, after a long approval cycle.  As an alternative, I decided to use Telegram, a messaging app that is very similar as WhatsApp.  This messaging app has a solid API.
  • I don’t have any front end skills.  Because I wanted to keep the solution as simple as possible, I decided to display the pictures through the old-fashioned Windows screensaver capabilities.  The slideshow screensaver is connected to a local folder that is synchronized via OneDrive.

The solution

This is the high level solution diagram:

Telegram

  1. Family members can share pictures and messages via a Telegram group.  One of the members in this group is the bot that takes care of the automation.  The bot is configured to forward the incoming messages via webhooks to Logic Apps.
  2. The Logic App receives the webhook messages.  In case the message contains a picture, the picture is downloaded via the Telegram API.  When the message contains text, this text is converted into an image using the img4me API, I’ve found online.  In this way, we will be able to send text messages to our grandmother.
  3. The pictures are uploaded to a specific folder in a dedicated OneDrive account.  Pictures are prefixed with “picture_”, text pictures are prefixed with “text_”.  Another Logic App runs on a daily basis and removes text pictures older than one day and pictures older than one week.  In this way, the most recent pictures are shared.
  4. My grandmother has a PC in her room that is configured with a screensaver slideshow.  The screensaver is connected to a folder that is synchronized via OneDrive.

Creating the bot

You can create your own bot by chatting to the @BotFather.  You have to send the message ”/newbot” and the @BotFather requests all required information.

Bot

With this token, you can register your webhook via this API call;

POST https://api.telegram.org/bot<token>/setWebhook
{
   "url":"<logicapps-request-url>"
}

When you are sending messages to the bot, you receive a webhook that looks like this:

{

  "update_id": 6631947,
  "message": {
    "message_id": 4,
    "from": {
      "id": 105*****73,
      "is_bot": false,
      "first_name": "Toon",
      "language_code": "en"
    },
    "chat": {
      "id": 105*****73,
      "first_name": "Toon",
      "type": "private"
    },
    "date": 1584036757,
    "text": "Hello world!!!"
  }
}

Configuring the Logic App

The Logic App starts with a parallel processing.  One branch gets executed when the message contains a picture.  The other branch is responsible to handle plain text messages.

Overview

Handle pictures

The expression to determine whether there’s a picture in the message looks like this:

"not": {
   "equals": [
      "@coalesce(triggerBody()?.message?.photo, 'No')",
      "No"
   ]
}

These are the steps that are executed to upload the picture to OneDrive:

Picture

  • The “Get Picture Metadata” performs the following API call:
POST https://api.telegram.org/bot<token>/getFile
{
  "file_id": "@{last(triggerBody().message.photo).file_id}"
}
  • The “Download Picture” performs this HTTP request:
GET concat('https://api.telegram.org/file/bot<token>/', body('Get_Picture_Metadata').result.file_path)
  • The “Upload image to OneDrive” creates uploads the picture with this file name:
@concat('picture_', guid(), '.jpg')

Handle text messages

The expression to determine whether the message is plain text looks like this:

"not": {
   "equals": [
      "@coalesce(triggerBody()?.message?.text, 'No')",
      "No"
   ]
}
These are the steps that are executed to convert text into a picture on OneDrive:

Text

  • The “Convert text into picture” performs this API call:
GET http://api.img4me.com/?text=@{triggerBody()?['message']?['text']}&font=tahoma&fcolor=FFFFFF&size=35&bcolor=000000&type=png
  • The “Download text picture” performs this HTTP request
GET @{body('Convert_text_into_picture')}
  • The “Upload image to OneDrive” creates uploads the picture with this file name:
@concat('text_', guid(), '.jpg')

Configuring the screensaver

This is how I configured the screensaver in Windows:

Screensaver

UPDATE: after a little dry-run, it appeared that the Windows screensaver is caching the pictures, so it’s not picking up automatically the newly added pictures.  After some research, I came across the free version of Photolive, which seems to be working perfectly!

Conclusion

Thanks to the serverless Logic Apps, this was very easy to setup.  At the time of writing, the solution is not yet in use by my grandmother.  I still have to deploy it on an old laptop and optimize the system, so it is really dummy proof (e.g. closing the laptop does not turn the pc to sleep).  After that, we’ll have to check if it will be possible to get this laptop in the room of my grandmother and have it connected to the internet.  Fingers crossed… Hopefully the retention house personnel wants to collaborate.

UPDATE: the laptop has been installed in the room of my grandmother.  We receive signals that she really enjoys to see the adventures of her great-grandchildren 🙂

Cheers
Toon

About me

Hi! I’m Toon Vanhoutte, a hands-on Azure architect – based in Belgium – with a big passion for teaching and helping people out. I’m happy to assist you during your Azure journey with high-quality advisory and I would love to teach you Azure’s possibilities via my tailored training courses.

Subscribe to the blog