Forward WhatsApp Mesaage as SMS or EMail

General discussions about Automagic and automation in general

Moderator: Martin

Post Reply
pummelfee
Posts: 1
Joined: 22 Mar 2018 07:29

Forward WhatsApp Mesaage as SMS or EMail

Post by pummelfee » 23 Mar 2018 05:58

I dont get it, and i appreciate your help.

How can i forward a whatsapp message by email or sms? i tried it with the notifications, but what i get is just an email with "xyz have sent xx new messages" and not the original message.

My dream would be kind of gateway, were whatsapp massages are forwarded with the senders name AND number by sms and/or email.

If someone wonders about the sense of this; i am frequently in an environment were i cannot go online and sort of whatsapp alert by sms would be great.

User avatar
Desmanto
Posts: 2188
Joined: 21 Jul 2017 17:50

Re: Forward WhatsApp Mesaage as SMS or EMail

Post by Desmanto » 23 Mar 2018 18:40

It can be done, someone from other forum has done it. He even forwarded it to another whatsapp number.

To know which variable to use, you can attach a debug dialog to the notification trigger. But sometimes it is too painful to check the message as they arrive. That's why I created the variable logger flow to log those variable.
viewtopic.php?f=3&t=7285
The flow already logging for whatsapp, so you don't need to change the trigger anymore.

Depends on your phone, the ROM and notification settings, the variables which containt the sender name/number and the message can differ a bit. At my phone, the message is stored at notification_text and the name or the number is stored at content_title. Use expression to check this. Depends on your country code, it might be a little different. We can use regex, but I think it better to check if the number start with 0 or +. If it is, then it is number, you haven't store the contact name yet. Directly use the number and put the name the same as the phone number. If it is group message, it will have " @ " attached to it, you must skip it and use the put the phone number as "group message" or anything.

But if it has name without @, it is individual chat, we need to find out the phone number. Use this name and put it at Action Query Content Provider. Just make sure you don't have any duplicate name. Make them different if there is.
Action : Query Content Provider
Content URI : content://com.android.contacts/data/phones
Projection : account_type,display_name,data4
Selection : account_type = ? and display_name = ?
Selection Arguments : com.whatsapp,{content_title}
Result Type : List
Variable : phone_number_list

This will query your contact, find at the whatsapp contact for the name you have. The result is the phone_number_list will contain the phone number. To use this query easily, simply press EXAMPLES, choose Phone numbers by contact name. The field maybe can be different in each phone. So sometimes you have to modify the Projection. You can find it out by using the same query Content Provider and test find the name you have.

Action : Query Content Provider
Content URI : content://com.android.contacts/data/phones
Result Type : Table
Include header row : Check
Variable : phone_number_list
Put a debug dialog after this and find the element index. Each column of the data have its name and value. Find the value you need. At mine, the number is located at index 47. Searching to the header, I found index 47 has the header "data4". that's why I use this as the projection.

Since it is a table, phone_number_list will result in list type. the phone name is located at the 3rd element (index 2). Use

Code: Select all

number = phone_number_list[2];
Then you need to find the message too. The message should be at the notification_text. But it contains the sender name too. So you need to replace it out with the content_title. The result text has some unnecessary spacing, you can trim it out.

Code: Select all

message = replace(notification_text, content_title, "");
message = trim(message);
The result now is you have
content_title : name of the sender
phone_number : phone number of the sender
message : message received.
Use them at the send sms or mail with gmail or anywhere you need.


Multiple messages
Problem arises when the message arrived consecutively before you can open the whatsapp (and clear the notification). This is what you have experienced above. When the message stacked up, especially from groups, you often see whatsapp compact the notification to "10 new messages". This won't show the content of the message anymore.

So if you are committed to use this flow to auto forward all whatsapp message, I am sure you don't care about the notification anymore. You must process the message as soon as it arrives and at the end of the flow, remove whatsapp notification (so it doesn't stacked up). Every time message arrive, notify for a while, got processed and notificaton removed. You will never have whatsapp notification left anymore. But if you need it, you can actually mirror the notification by creating the exact same notification in Automagic using all variables provided by whatsapp notification. The difference is, this won't stacked up and ruin the flow. Because you can just need to be informed that you have unread whatsapp messages, doesn't necessary need to know from where (since you have forwarded them already).

Flow Execution Policy can be set to "wait", to ensure each notification processed properly.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), Resurrection Remix Official 7.0.2 20190829, Pie 9.0, Rooted.

Post Reply