Zapier to Twilio to generate Dynamic SMS body












0















I would like to use Zapier to send an SMS via Twilio with a dynamic body containing different affiliate referral link to an app every time I get a new subscriber to my mailchimp mailing list.



I have two separate bits of code that do what I am looking for but, due to the limitations of installing modules within the code automation in Zapier and my lack of experience in programming i dont know how to bring the two together in a Zapier code Zap.



This is the code I can use to send an SMS with Twilio and works fine independently:



const accountSid = '<twilioAcctSid>';
const authToken = '<twilioAuthToken>';
const client = require('twilio')(accountSid, authToken);

client.messages
.create({from: '<twilPhoneNo>', body: '<affiliateRefLink>', to: '<subscriberPhoneNo>' })
.then(message => console.log(message.sid))
.done();


This is the code I have used elsewhere to randomly select one of my affiliate links and I would like include a random link in the body of the SMS to the new subscriber.



const refCodes = ['link1',
'link2',
'link3'];

function getCode()
{
let randomNum = Math.floor((Math.random() * refCodes.length));
let baseSite = "#url_";
let newLink = baseSite + refCodes[randomNum];
document.getElementById('#url').href = newLink;
document.getElementById('#url').innerHTML = newLink;

}


Any help would be sincerely appreciated!



Toes.










share|improve this question





























    0















    I would like to use Zapier to send an SMS via Twilio with a dynamic body containing different affiliate referral link to an app every time I get a new subscriber to my mailchimp mailing list.



    I have two separate bits of code that do what I am looking for but, due to the limitations of installing modules within the code automation in Zapier and my lack of experience in programming i dont know how to bring the two together in a Zapier code Zap.



    This is the code I can use to send an SMS with Twilio and works fine independently:



    const accountSid = '<twilioAcctSid>';
    const authToken = '<twilioAuthToken>';
    const client = require('twilio')(accountSid, authToken);

    client.messages
    .create({from: '<twilPhoneNo>', body: '<affiliateRefLink>', to: '<subscriberPhoneNo>' })
    .then(message => console.log(message.sid))
    .done();


    This is the code I have used elsewhere to randomly select one of my affiliate links and I would like include a random link in the body of the SMS to the new subscriber.



    const refCodes = ['link1',
    'link2',
    'link3'];

    function getCode()
    {
    let randomNum = Math.floor((Math.random() * refCodes.length));
    let baseSite = "#url_";
    let newLink = baseSite + refCodes[randomNum];
    document.getElementById('#url').href = newLink;
    document.getElementById('#url').innerHTML = newLink;

    }


    Any help would be sincerely appreciated!



    Toes.










    share|improve this question



























      0












      0








      0








      I would like to use Zapier to send an SMS via Twilio with a dynamic body containing different affiliate referral link to an app every time I get a new subscriber to my mailchimp mailing list.



      I have two separate bits of code that do what I am looking for but, due to the limitations of installing modules within the code automation in Zapier and my lack of experience in programming i dont know how to bring the two together in a Zapier code Zap.



      This is the code I can use to send an SMS with Twilio and works fine independently:



      const accountSid = '<twilioAcctSid>';
      const authToken = '<twilioAuthToken>';
      const client = require('twilio')(accountSid, authToken);

      client.messages
      .create({from: '<twilPhoneNo>', body: '<affiliateRefLink>', to: '<subscriberPhoneNo>' })
      .then(message => console.log(message.sid))
      .done();


      This is the code I have used elsewhere to randomly select one of my affiliate links and I would like include a random link in the body of the SMS to the new subscriber.



      const refCodes = ['link1',
      'link2',
      'link3'];

      function getCode()
      {
      let randomNum = Math.floor((Math.random() * refCodes.length));
      let baseSite = "#url_";
      let newLink = baseSite + refCodes[randomNum];
      document.getElementById('#url').href = newLink;
      document.getElementById('#url').innerHTML = newLink;

      }


      Any help would be sincerely appreciated!



      Toes.










      share|improve this question
















      I would like to use Zapier to send an SMS via Twilio with a dynamic body containing different affiliate referral link to an app every time I get a new subscriber to my mailchimp mailing list.



      I have two separate bits of code that do what I am looking for but, due to the limitations of installing modules within the code automation in Zapier and my lack of experience in programming i dont know how to bring the two together in a Zapier code Zap.



      This is the code I can use to send an SMS with Twilio and works fine independently:



      const accountSid = '<twilioAcctSid>';
      const authToken = '<twilioAuthToken>';
      const client = require('twilio')(accountSid, authToken);

      client.messages
      .create({from: '<twilPhoneNo>', body: '<affiliateRefLink>', to: '<subscriberPhoneNo>' })
      .then(message => console.log(message.sid))
      .done();


      This is the code I have used elsewhere to randomly select one of my affiliate links and I would like include a random link in the body of the SMS to the new subscriber.



      const refCodes = ['link1',
      'link2',
      'link3'];

      function getCode()
      {
      let randomNum = Math.floor((Math.random() * refCodes.length));
      let baseSite = "#url_";
      let newLink = baseSite + refCodes[randomNum];
      document.getElementById('#url').href = newLink;
      document.getElementById('#url').innerHTML = newLink;

      }


      Any help would be sincerely appreciated!



      Toes.







      javascript node.js twilio twilio-api zapier






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 20 at 10:35







      xXUnderToesXx

















      asked Jan 20 at 10:10









      xXUnderToesXxxXUnderToesXx

      12




      12
























          2 Answers
          2






          active

          oldest

          votes


















          0














          Twilio developer evangelist here.



          I'm not sure you can run custom code like that within Zapier. However, what I might suggest is that you use the Zapier webhook module combined with a Twilio Function.



          Twilio Functions give you a serverless way of running custom Node.js based code, so you could combine the two pieces of code you have above in one Function that is then called by the Zapier webhook. Alternatively, if MailChimp allow you to setup your own webhooks you could circumvent Zapier entirely and point it straight at your Twilio Function.



          Let me know if that helps at all.






          share|improve this answer
























          • David here, from the Zapier Platform team. This sounds like a great approach! One point of clarification - Zapier code steps can't use external node modules (such as twilio) but custom CLI apps can! You could make my great twilio CLI app that runs whatever you need with whatever modules.

            – xavdid
            Jan 23 at 16:43











          • Thanks very much for your feedback guys, sincerely appreciated! I will look further into the above information!!!

            – xXUnderToesXx
            Jan 28 at 4:25



















          0














          Thanks @philnash for your support, I was able to solve this with the code below!



            exports.handler = function(context, event, callback) {
          const appCodes = ['code1', 'code2', 'code3', 'code4']
          var smsBody = refCode ();
          var subNum = event.primaryPhone || 'There is no subscriber number'; // primaryPhone sent via HTTP post to twilio function

          function refCode () {
          return appCodes[Math.floor((Math.random() * appCodes.length))];
          };

          context.getTwilioClient().messages.create({
          to: `${subNum}`, // parameters & values recieved from HTTP POST are available within the twilio functions "event" context
          from: '+1444555666',
          body: `Get the App: ${smsBody}`
          }).then(msg => {
          callback(null, msg.sid);
          }).catch(err => callback(err));
          }





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54275393%2fzapier-to-twilio-to-generate-dynamic-sms-body%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Twilio developer evangelist here.



            I'm not sure you can run custom code like that within Zapier. However, what I might suggest is that you use the Zapier webhook module combined with a Twilio Function.



            Twilio Functions give you a serverless way of running custom Node.js based code, so you could combine the two pieces of code you have above in one Function that is then called by the Zapier webhook. Alternatively, if MailChimp allow you to setup your own webhooks you could circumvent Zapier entirely and point it straight at your Twilio Function.



            Let me know if that helps at all.






            share|improve this answer
























            • David here, from the Zapier Platform team. This sounds like a great approach! One point of clarification - Zapier code steps can't use external node modules (such as twilio) but custom CLI apps can! You could make my great twilio CLI app that runs whatever you need with whatever modules.

              – xavdid
              Jan 23 at 16:43











            • Thanks very much for your feedback guys, sincerely appreciated! I will look further into the above information!!!

              – xXUnderToesXx
              Jan 28 at 4:25
















            0














            Twilio developer evangelist here.



            I'm not sure you can run custom code like that within Zapier. However, what I might suggest is that you use the Zapier webhook module combined with a Twilio Function.



            Twilio Functions give you a serverless way of running custom Node.js based code, so you could combine the two pieces of code you have above in one Function that is then called by the Zapier webhook. Alternatively, if MailChimp allow you to setup your own webhooks you could circumvent Zapier entirely and point it straight at your Twilio Function.



            Let me know if that helps at all.






            share|improve this answer
























            • David here, from the Zapier Platform team. This sounds like a great approach! One point of clarification - Zapier code steps can't use external node modules (such as twilio) but custom CLI apps can! You could make my great twilio CLI app that runs whatever you need with whatever modules.

              – xavdid
              Jan 23 at 16:43











            • Thanks very much for your feedback guys, sincerely appreciated! I will look further into the above information!!!

              – xXUnderToesXx
              Jan 28 at 4:25














            0












            0








            0







            Twilio developer evangelist here.



            I'm not sure you can run custom code like that within Zapier. However, what I might suggest is that you use the Zapier webhook module combined with a Twilio Function.



            Twilio Functions give you a serverless way of running custom Node.js based code, so you could combine the two pieces of code you have above in one Function that is then called by the Zapier webhook. Alternatively, if MailChimp allow you to setup your own webhooks you could circumvent Zapier entirely and point it straight at your Twilio Function.



            Let me know if that helps at all.






            share|improve this answer













            Twilio developer evangelist here.



            I'm not sure you can run custom code like that within Zapier. However, what I might suggest is that you use the Zapier webhook module combined with a Twilio Function.



            Twilio Functions give you a serverless way of running custom Node.js based code, so you could combine the two pieces of code you have above in one Function that is then called by the Zapier webhook. Alternatively, if MailChimp allow you to setup your own webhooks you could circumvent Zapier entirely and point it straight at your Twilio Function.



            Let me know if that helps at all.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 21 at 3:10









            philnashphilnash

            38.2k93454




            38.2k93454













            • David here, from the Zapier Platform team. This sounds like a great approach! One point of clarification - Zapier code steps can't use external node modules (such as twilio) but custom CLI apps can! You could make my great twilio CLI app that runs whatever you need with whatever modules.

              – xavdid
              Jan 23 at 16:43











            • Thanks very much for your feedback guys, sincerely appreciated! I will look further into the above information!!!

              – xXUnderToesXx
              Jan 28 at 4:25



















            • David here, from the Zapier Platform team. This sounds like a great approach! One point of clarification - Zapier code steps can't use external node modules (such as twilio) but custom CLI apps can! You could make my great twilio CLI app that runs whatever you need with whatever modules.

              – xavdid
              Jan 23 at 16:43











            • Thanks very much for your feedback guys, sincerely appreciated! I will look further into the above information!!!

              – xXUnderToesXx
              Jan 28 at 4:25

















            David here, from the Zapier Platform team. This sounds like a great approach! One point of clarification - Zapier code steps can't use external node modules (such as twilio) but custom CLI apps can! You could make my great twilio CLI app that runs whatever you need with whatever modules.

            – xavdid
            Jan 23 at 16:43





            David here, from the Zapier Platform team. This sounds like a great approach! One point of clarification - Zapier code steps can't use external node modules (such as twilio) but custom CLI apps can! You could make my great twilio CLI app that runs whatever you need with whatever modules.

            – xavdid
            Jan 23 at 16:43













            Thanks very much for your feedback guys, sincerely appreciated! I will look further into the above information!!!

            – xXUnderToesXx
            Jan 28 at 4:25





            Thanks very much for your feedback guys, sincerely appreciated! I will look further into the above information!!!

            – xXUnderToesXx
            Jan 28 at 4:25













            0














            Thanks @philnash for your support, I was able to solve this with the code below!



              exports.handler = function(context, event, callback) {
            const appCodes = ['code1', 'code2', 'code3', 'code4']
            var smsBody = refCode ();
            var subNum = event.primaryPhone || 'There is no subscriber number'; // primaryPhone sent via HTTP post to twilio function

            function refCode () {
            return appCodes[Math.floor((Math.random() * appCodes.length))];
            };

            context.getTwilioClient().messages.create({
            to: `${subNum}`, // parameters & values recieved from HTTP POST are available within the twilio functions "event" context
            from: '+1444555666',
            body: `Get the App: ${smsBody}`
            }).then(msg => {
            callback(null, msg.sid);
            }).catch(err => callback(err));
            }





            share|improve this answer




























              0














              Thanks @philnash for your support, I was able to solve this with the code below!



                exports.handler = function(context, event, callback) {
              const appCodes = ['code1', 'code2', 'code3', 'code4']
              var smsBody = refCode ();
              var subNum = event.primaryPhone || 'There is no subscriber number'; // primaryPhone sent via HTTP post to twilio function

              function refCode () {
              return appCodes[Math.floor((Math.random() * appCodes.length))];
              };

              context.getTwilioClient().messages.create({
              to: `${subNum}`, // parameters & values recieved from HTTP POST are available within the twilio functions "event" context
              from: '+1444555666',
              body: `Get the App: ${smsBody}`
              }).then(msg => {
              callback(null, msg.sid);
              }).catch(err => callback(err));
              }





              share|improve this answer


























                0












                0








                0







                Thanks @philnash for your support, I was able to solve this with the code below!



                  exports.handler = function(context, event, callback) {
                const appCodes = ['code1', 'code2', 'code3', 'code4']
                var smsBody = refCode ();
                var subNum = event.primaryPhone || 'There is no subscriber number'; // primaryPhone sent via HTTP post to twilio function

                function refCode () {
                return appCodes[Math.floor((Math.random() * appCodes.length))];
                };

                context.getTwilioClient().messages.create({
                to: `${subNum}`, // parameters & values recieved from HTTP POST are available within the twilio functions "event" context
                from: '+1444555666',
                body: `Get the App: ${smsBody}`
                }).then(msg => {
                callback(null, msg.sid);
                }).catch(err => callback(err));
                }





                share|improve this answer













                Thanks @philnash for your support, I was able to solve this with the code below!



                  exports.handler = function(context, event, callback) {
                const appCodes = ['code1', 'code2', 'code3', 'code4']
                var smsBody = refCode ();
                var subNum = event.primaryPhone || 'There is no subscriber number'; // primaryPhone sent via HTTP post to twilio function

                function refCode () {
                return appCodes[Math.floor((Math.random() * appCodes.length))];
                };

                context.getTwilioClient().messages.create({
                to: `${subNum}`, // parameters & values recieved from HTTP POST are available within the twilio functions "event" context
                from: '+1444555666',
                body: `Get the App: ${smsBody}`
                }).then(msg => {
                callback(null, msg.sid);
                }).catch(err => callback(err));
                }






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Feb 3 at 9:30









                xXUnderToesXxxXUnderToesXx

                12




                12






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54275393%2fzapier-to-twilio-to-generate-dynamic-sms-body%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Homophylophilia

                    Updating UILabel text programmatically using a function

                    Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage