Sending a message to WhatsApp

WhatsApp is one of the hottest new apps this year. It lets you send messages to other WhatApp users via the net. It has over 500 million active users, with 700 million messages sent each day.

WhatsApp has an API, so you can hook it into your AppStudio app. It has two functions: open the WhatsApp app from your AppStudio App, and send a message to WhatsApp.

Here’s how our test app looks:
Screen Shot 2014-08-14 at 9.39.13 AM

The “Open WhatsApp” button takes us directly to the WhatsApp app. The code for it is

Function Button1_onclick()
  location = "whatsapp://app"
End Function

The Send button sends a message via WhatsApp. The SendTo field requires that you know the WhatsApp address book ID for the user: since WhatsApp has no easy way to get these numbers, leave this field blank or don’t include it at all in your app.

The Message field has the text you want to send. As far as we can tell, only text is supported at this time: it does not appear to be possible to send images.

Here’s the code for the Send button:

Function Button2_onclick()
  Dim s  
  s = "whatsapp://send?text=" & encodeURIComponent(txtMessage.text)
  If txtSendTo.text<>"" Then 
    s = s & "?abid=" & encodeURIComponent(txtSendTo.text)
  End If
  location = s
End Function

When you click on Send, WhatsApp opens and you can select the user you want to send the message to. The text in Message will be passed through to WhatsApp.