WhatsApp messaging?

Hi guys,

Maybe one of your did this before, but we know that we can make a call through a commcare call out
https://confluence.dimagi.com/display/commcarepublic/Making+a+Phone+Call+from+CommCare+Android

is it possible to compose a new Whatsapp message with the phone number already entered? anyone tried that successfully? I imagine we just need to change this bit

“android.intent.action.CALL”
and use a different intent, but not sure if CommCare App supports it

Mazz

Hey Mazz,

On my phone most phone operations allow the user to choose a dialer, I haven’t tested with CommCare yet but I would have expected that to be the case for our app as well based on how we construct the intent.

Is it because we are using the direct call intent here instead of a different one?

Hey Calyton,

I saw that in order to make a call “open a dialer” with the explicit action “CALL”. doing some googling about i found that i could compose a message in whatsapp with a provided number leveraging the same infrastructure “Android.Intent” while adding a bunch of other parameters to get it to skip the selection and go directly into WhatsApp.

So i’m assuming that when the functionality was built into CommCare, it didn’t really intend for intent to be used beyond that intention of making a call “That’s a tongue twister”. So before i go down this rabbit hole, i just wanted to confirm if it was possible to some how compose a whatsapp message with a number loaded in through a commcare form. would allow me to capture a few more interactions with my cases as well as make my field staff’s lives a lot easier (no cause to record beneficiary phone numbers in their address book and so on)

Do you recommend i go down this rabbit hole and see what i find out?

Mazz

Hi Mazz,

Annoying that Whatsapp has their own bespoke intent for this :confused:

We do support Custom Android Callouts to some extent, but I'm not sure if we have all of the right pieces set up to make it work with whatsapp.

Some quick reading implies that it's possible that on device whatsapp may be set up to handle url based callouts.

If so you can take advantage of the markdown question formatting for this, I think if you inject a link, like:

Call from Whatsapp

In your form question text, that clickable link might launch a call. Don't quite have a phone handy to test right now, but should be quick to see if it works.

-Clayton

Ah, reading a bit more here, it looks like whatsapp supports sending TEXT messages from callouts, but doesn’t support triggering a call. StackOverflow is full of people sharing potential tricks to do so, but I don’t see any that seem to be confirmed successful. Let me know if there’s anything I’ve missed, but it looks like WhatsApp is kind of explicitly designed to not allow this :/.

i’m gonna give that question formatting options and see if a URL would do the trick. it sounds promising, but i feel that it’ll depend on what browser was installed on the device. it theoretically should do the trick. i know you can format a URL to start a new message in whatsapp if you had it open on your browser. i just gotta find out if it would behave the same way over the mobile device “call the web page, that opens a browser, that tries to send a whatsapp message, which then asks which composer you wish to use”.

i’m likely to try this in the next few days. will keep this alive with results

Mazz

Hey Calyton,

Markdown works! just a URL using https://wa.me/phonenumber is enough! it’ll start a whatsapp chat with the number preloaded. looks like you can add text too into the message body.

This is actually pretty awesome as we can use this functionality to both not let the user have a reason to record a beneficiary’s phone number as a contact, as well as being able to notify the beneficiary of information such as their ID or whatever relevant piece of information to the service delivery!

Awesome!

Just a thought that crossed my mind now, you know what would be pretty bada$$ though?

Capturing the “click” event and allowing us to do something with it like increment a counter or change a value somewhere or even just use the function “depend()”

Ooooh!

so i’m following up on this topic to let you guys who want to do this know a few things about this approach

1- the message contents have to be URL encoded. so space characters have to become %20, and most of the other special characters, as well as arabic text or other languages. essentially, you need to be able to use it as an actual URL pointer.
2- If the device running this is NOT connected to the internet, whats app will return a message saying that it can’t resolve the phone number because of your internet connection. a real bummer. so, you’ll likely have to do this in a form that the users can use later on if they are working in a disconnected environment.
3- the phone number used has to use countrycode and have no leading 0’s or + signs. otherwise, Whatsapp won’t honor your request.
4- This is really cool when it does work. a good resource to encode your text into the correct format is this site -> https://www.urlencoder.org/

and a question to more experienced people with the translate function:
do you think it’s possible to use it to replace specific characters with their url-encoded counterparts? is there a limit on the length of the parameters?
if it’s possible, this is something that could be useful to create a function for called something along the lines of “encode-url(text)”

HTH

Mazz