Categories
Mobile Software Engineering VAS

How to Open SMS with Prefilled Message and Receiver with Javascript

If you have a shortcode you are promoting and you want a better conversion let say “HOW” to 700, one of the ways you can go about is to take advantage of prefill SMS.

First, set up a landing page with a call to action link that says SEND or whatever, such that if your user clicks the link on the browser, it automatically opens the SMS app on their phone with a prefilled receiver e.g the shortcode 700,  and a prefilled keyword, e.g  HOW in the message body.

SMS URI Scheme

To help us achieve this, you need to understand the SMS URI scheme which is similar to a Web link with HTTP/HTTPS

  • For Android, you have sms:{Receiver}?body={encoded message} e.g sms:700?body=HOW
  • For IOS 8 and above, you have sms:{Receiver}&body={encoded message} e.g sms:700&body=HOW
  • For older IOS like IOS 5 & 6, you have sms:{Receiver};body={encoded message} e.g sms:700;body=HOW

You can now set the link of a tag as any of this depending on your device, for Android: <a href=”sms:700?body=HOW”>Send SMS</a>

var ua = navigator.userAgent.toLowerCase();
var href = "";

if (typeof operamini !== "undefined") {

        if (ua.indexOf("iphone") > -1 || ua.indexOf("ipad") > -1) {

                href = "sms:700";

         }

         else {

             href = "sms:700?body=HOW";

            }

        }

        else {

            if (ua.indexOf("iphone") > -1 || ua.indexOf("ipad") > -1) {
                href = "sms:700&body=HOW";
            }
            else {
                href = "sms:700?body=HOW";
            }
        }
        var smsLink = document.querySelector("a#sms");
        smsLink.setAttribute("href", href);

Opera Mini Browser SMS Support

Opera Mini is one of the most used browsers in Africa for obvious reasons and it is a browser that treats javascript differently, so it provides SMS support using the code below

if (operamini.features.sms) {
      operamini.sms.number = "700";
      operamini.sms.body = "HOW";
}

 

1 reply on “How to Open SMS with Prefilled Message and Receiver with Javascript”

Leave a Reply