3 steps to send SMS from Knack!

Intended audience: developers with medium-level skills in NodeJS, JavaScript, and Knack.

 

Hello folks!

Setting up Knack for message sending it’s possible. With this post, we'll show you how with these three easy steps:

  1. A Twilio account with a phone number ($1) and enough credits to test ($20)
  2. A cloud server to run your own end-point. We used NodeJS in this example.
  3. Your Knack app with an object and form to post the request to the end-point

 

Step 1: Setup Twilio

First of all you must have a Twilio account to create a project and purchase a phone number for that project. Each project has credentials that are needed to make the request from the backend, that is an account id and a token.

![](upload://hrTIbHdzm40tIipNQTydQggNV1G.png)

 

Step 2: Create the NodeJS endpoint

Once your Twilio account is ready, you want to create the endpoint that will receive the message and phone number from Knack, and forward it to Twilio API. 

The code in the endpoint will look like this.

![](upload://tuEX9H7MPuq6u1IOxOnTC6v3qqe.png)

 

To see the code’s structure please enter this site: https://github.com/SOLUNTECH/Knack-to-Endpoint-to-Twillio 

 

Step 3: Create the object and form in Knack

Now, you need to work in Knack to post the message to the endpoint. First, let’s create the object in the database with the simple fields.

![](upload://xE52E350YcYM8CYMlOyfFbIVwT9.png)

Now, create a page and put a form to post to the object you just created.

![](upload://w1K5qwgNoxAHL1leMUNF9L9w3L4.png)

Finally, go to the JavaScript section in Knack, and add this simple code. Make sure you update the field_id with your own.

 // Server URL

var TEST_SERVER_URL = 'https://xxxxxxxxxxxx.xxx/api/v1/';

// Knack event listener

$(document).on('knack-form-submit.view_xxx', async function (event, view, data) {

//Ajax request to the nodejs server

await $.ajax({

url: `${TEST_SERVER_URL}twiliosms`, // Endpoint URL

type: 'POST', // Method

data: { // Body JSON

message: data.field_301,

to: data.field_300_raw.full

},

dataType: 'json'

});

});

Troubleshooting

If you can’t see the SMS coming , it may be due to multiple variables, however these are the 3 most common ones: 

  • Internet failure 
  • Server error
  • Bad implementation of the Knack code

![](upload://vJj5aoNVgqumo2lfEqKW0jp955t.png)

 

Want to know how it works?

Enter https://soluntech.knack.com/test#test-sms/ and test it yourself.

 

If you liked this, please leave a comment below, we’d love to read it!

 

 

Hi Bob. I didn't follow up with Soluntech's solution so I can't comment on that. I've ended up using Integromat with Knack. If you haven't tried out Integromat, you should! It works with Knack's API very well and extends Knack's capabilities in a low/no-code way. (It's very similar to Zapier, but I now prefer to use Integromat)

8891680807 I am trying to figure this out too. Have you had any luck figuring anything out?

 

Hi Tanner, with some customization it should be possible. Let's get in touch and see what's required. Here's our email hello@soluntech.com. All best.

I'm trying to figure out a way to pull multiple phone numbers from connected records and send an SMS to multiple recipients (via Twilio). I have not been able to figure it out. Would this tool be able to do that?

Thanks David. We're doing some updates to prevent misuse of the tool.

Beware: implementing this as-is means there is nothing checking the validity of the SMS being sent. This means anyone would be able to use the endpoint you've created to send SMS messages using your Twilio account, causing you to incur the fees for those messages.
The best way to go about this would be to periodically retrieve the records for which you are sending the messages and generate the messages server-side, instead.