0

My form will only send to 10 digit US numbers. I'd like to send to Intl numbers once the country is selected. After looking through the Intl-Tel-Input docs, this code might be needed but I'm not having any luck with it: myInput.val(myInput.intlTelInput("getNumber"));

Here is the Branch.io text me the app doc, which is mostly the code below with the update of using phoneSMS.

How do I send to Intl numbers using branch.io and Intl-Tel-Input?

 <script type="text/javascript">
            (function(b,r,a,n,c,h,_,s,d,k){if(!b[n]||!b[n]._q){for(;s<_.length;)c(h,_[s++]);d=r.createElement(a);d.async=1;d.src="https://cdn.branch.io/branch-latest.min.js";k=r.getElementsByTagName(a)[0];k.parentNode.insertBefore(d,k);b[n]=h}})(window,document,"script","branch",function(b,r){b[r]=function(){b._q.push([r,arguments])}},{_q:[],_v:1},"addListener applyCode banner closeBanner creditHistory credits data deepview deepviewCta first getCode init link logout redeem referrals removeListener sendSMS setIdentity track validateCode".split(" "), 0);
branch.init('YOUR-BRANCH-KEY');

            function sendSMS(form) {
                var phone = form.phoneSMS.value;
                var linkData = {
                    tags: [],
                    channel: 'Website',
                    feature: 'TextMeTheApp',
                    data: {
                        'foo': 'bar'
                    }
                };
                var options = {};
                var callback = function(err, result) {
                    if (err) {
                        alert("Sorry, something went wrong.");
                    }
                    else {
                        alert("SMS sent!");
                    }
                };
                branch.sendSMS(phone, linkData, options, callback);
                form.phone.value = "";
            }
        </script>

HTML

<form onsubmit="sendSMS(this); return false;">
<input type="tel" name="phoneSMS" id="phoneSMS">
<input type="submit"/>
</form>

Intl Tel Input plugin:

<script type="text/javascript" src="{{ site.baseurl }}js/intlTelInput.js"></script> 
  <script>
      $("#phoneSMS").intlTelInput({
        utilsScript: "{{ site.baseurl }}/js/utils.js"
      });
  </script>
evan
  • 954
  • 3
  • 18
  • 37

2 Answers2

2

Alex from Branch.io here: Branch does support international phone numbers with the text-me-the-app feature, and we're hoping to have a country selector like Intl-Tel-Input integrated at some point soon.

For right now, you need to append the country code and + manually. We have a section describing this on our docs here (it's a little buried...sorry!). Basically you need to update that snippet with var phone = "+91" + form.phone.value; like so:

<script type="text/javascript">
           (function(b,r,a,n,c,h,_,s,d,k){if(!b[n]||!b[n]._q){for(;s<_.length;)c(h,_[s++]);d=r.createElement(a);d.async=1;d.src="https://cdn.branch.io/branch-latest.min.js";k=r.getElementsByTagName(a)[0];k.parentNode.insertBefore(d,k);b[n]=h}})(window,document,"script","branch",function(b,r){b[r]=function(){b._q.push([r,arguments])}},{_q:[],_v:1},"addListener applyCode banner closeBanner creditHistory credits data deepview deepviewCta first getCode init link logout redeem referrals removeListener sendSMS setIdentity track validateCode".split(" "), 0);
branch.init('YOUR-BRANCH-KEY');

           function sendSMS(form) {
               var phone = "+91" + form.phone.value;
               var linkData = {
                   tags: [],
                   channel: 'Website',
                   feature: 'TextMeTheApp',
                   data: {
                       'foo': 'bar'
                   }
               };
               var options = {};
               var callback = function(err, result) {
                   if (err) {
                       alert("Sorry, something went wrong.");
                   }
                   else {
                       alert("SMS sent!");
                   }
               };
               branch.sendSMS(phone, linkData, options, callback);
               form.phone.value = "";
           }
       </script>

In theory you should be able to feed the output of Intl-Tel-Input into that variable.

If you do get this working, please let me know! We'd love to get it incorporated directly into the SDK.

Alex Bauer
  • 13,147
  • 1
  • 27
  • 44
1

The easiest way you could accomplish prepending the number with the international prefix is instead of var phone = form.phoneSMS.value in your sendSMS() function to update it to ask the intlTelInput itself for the number - it gives you international format.

Example:

var phone = $('#phoneSMS').intlTelInput("getNumber")

For further reference, check out intlTelInput's public methods.

Leo Napoleon
  • 969
  • 6
  • 11