# How to send SMS to different number using Twilio?

**URL:** <https://discourse.nodered.org/t/how-to-send-sms-to-different-number-using-twilio/5111>\
**Category:** General\
**Created:** [22 November 2018 10:40 UTC](https://discourse.nodered.org/t/how-to-send-sms-to-different-number-using-twilio/5111 "2018-11-22T10:40:25Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Conard](https://avatars.discourse-cdn.com/v4/letter/c/41988e/32.png) [@Conard](https://discourse.nodered.org/u/Conard)\
**Post date:** [22 November 2018 10:40 UTC](https://discourse.nodered.org/t/how-to-send-sms-to-different-number-using-twilio/5111/1 "2018-11-22T10:40:25Z")

</div>

I have a database and its design is like this in my Microsoft SQL Database:  
 ![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/1/11fa32612a72f60df82cee10af679995b32d51bb.jpeg)

Once a student has scanned his fingerprint, the serial port will generate output like this:  
`{"SID":1,"Date":"20181121","Time":"01:54:54"}`

I would like to send a SMS to a student's parent after scanning finger, How can I do it??  
I would like to send the SMS to parents' phone number stored inside my database  
I have a Twilio account with me.

---

<div class="post-metadata">

**Author:** ![Conard](https://avatars.discourse-cdn.com/v4/letter/c/41988e/32.png) [@Conard](https://discourse.nodered.org/u/Conard)\
**Post date:** [22 November 2018 10:41 UTC](https://discourse.nodered.org/t/how-to-send-sms-to-different-number-using-twilio/5111/2 "2018-11-22T10:41:47Z")

</div>

I convert the serial output into object using JSON Node like this:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/6f6e7a6184ea46db6e8969475061b94577020fea.png)

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [22 November 2018 10:52 UTC](https://discourse.nodered.org/t/how-to-send-sms-to-different-number-using-twilio/5111/3 "2018-11-22T10:52:54Z")

</div>

So if you can identify the student, you would need to then do a database lookup to return the information you need. Then you would need to add the appropriate information to into a message and send that on to a Twilio node. Depending where you live you would also need to register the data you are keeping to comply with data protection legislation.

---

<div class="post-metadata">

**Author:** ![Conard](https://avatars.discourse-cdn.com/v4/letter/c/41988e/32.png) [@Conard](https://discourse.nodered.org/u/Conard)\
**Post date:** [22 November 2018 11:04 UTC](https://discourse.nodered.org/t/how-to-send-sms-to-different-number-using-twilio/5111/4 "2018-11-22T11:04:18Z")

</div>

My idea is using that SID, coming out from serial port.  
Then write an SELECT statement with INNER JOIN:  
SELECT p.PhoneNo  
FROM  
student s  
INNER JOIN student\_parent sp  
ON s.SID = sp.SID  
INNER JOIN parent p  
ON sp.PID = p.PID

Once I get the phone number, then send SMS to that phone number.

But I don't know how to do that, what node should I use? How the flow looks like?  
I only know MSSQL & Twilio are required

---

<div class="post-metadata">

**Author:** ![Conard](https://avatars.discourse-cdn.com/v4/letter/c/41988e/32.png) [@Conard](https://discourse.nodered.org/u/Conard)\
**Post date:** [22 November 2018 11:11 UTC](https://discourse.nodered.org/t/how-to-send-sms-to-different-number-using-twilio/5111/5 "2018-11-22T11:11:50Z")

</div>

My idea is using the SID, coming out from the serial port.  
Then write an SELECT statement with INNER JOIN to get parent phone number:  
`SELECT p.PhoneNo FROM student s INNER JOIN student_parent sp ON s.SID = sp.SID INNER JOIN parent p ON sp.PID = p.PID WHERE s.SID = ??`

And send the SMS to the parent based on the phone number stored in database  
But I don't know how to do it. What node should I use? How the flow design looks like?  
I only know MSSQL and Twilio Node are required

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [22 November 2018 11:27 UTC](https://discourse.nodered.org/t/how-to-send-sms-to-different-number-using-twilio/5111/6 "2018-11-22T11:27:02Z")

</div>

I've never used MSSQL, but I'd start by searching [flows.nodered.org](http://flows.nodered.org) for:  
"MSSQL"  
then try downloading one and trying.

---

<div class="post-metadata">

**Author:** ![Conard](https://avatars.discourse-cdn.com/v4/letter/c/41988e/32.png) [@Conard](https://discourse.nodered.org/u/Conard)\
**Post date:** [22 November 2018 13:45 UTC](https://discourse.nodered.org/t/how-to-send-sms-to-different-number-using-twilio/5111/7 "2018-11-22T13:45:34Z")

</div>

![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/d44ec62bf83eb0b0ba1fac3ca4bf10e5f04cf478.jpeg)

I can get the phone number now, how can I make it send SMS to the phone number I get?  
It seems like Twilio Node has no setting for me to write code on it

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [22 November 2018 13:59 UTC](https://discourse.nodered.org/t/how-to-send-sms-to-different-number-using-twilio/5111/8 "2018-11-22T13:59:46Z")

</div>

You shouldn't have two paths coming from your JSON node.  
As you are sending two messages to your MSSQL node (node-RED won't just "join" the messages back together again"

On the twilio question, have you read the info panel of the node? Our read the readme for the node on [flows.nodered.org](http://flows.nodered.org)?  
You can use the change node to move a property of the msg object

---

<div class="post-metadata">

**Author:** ![Conard](https://avatars.discourse-cdn.com/v4/letter/c/41988e/32.png) [@Conard](https://discourse.nodered.org/u/Conard)\
**Post date:** [22 November 2018 14:17 UTC](https://discourse.nodered.org/t/how-to-send-sms-to-different-number-using-twilio/5111/9 "2018-11-22T14:17:35Z")

</div>

Upper Template Node is storing attendance record to MSSQL  
Lower Template Node is getting parent's phone number from MSSQL by using SELECT statement I have mentioned above.

I'm using Debug Node to make sure that I can actually get the phone number from MSSQL, You can just ignore the second result (Undefined).

For now, I would like to use the phone number I get from MSSQL, and send SMS using Twilio Node. But Twilio Node can only put a `To` phone number in node properties, that means only one parent can get the SMS. All SMS will be received by only one phone number (parent), even not his/her children

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [22 November 2018 14:31 UTC](https://discourse.nodered.org/t/how-to-send-sms-to-different-number-using-twilio/5111/10 "2018-11-22T14:31:20Z")

</div>

You can use the message to define the sendto phone number as is described in the Nodes readme.  
(assuming you are using node-red-node-twilio)

---

<div class="post-metadata">

**Author:** ![Conard](https://avatars.discourse-cdn.com/v4/letter/c/41988e/32.png) [@Conard](https://discourse.nodered.org/u/Conard)\
**Post date:** [22 November 2018 16:16 UTC](https://discourse.nodered.org/t/how-to-send-sms-to-different-number-using-twilio/5111/11 "2018-11-22T16:16:13Z")

</div>

what do you mean? use debug node? I would like to send SMS to different number, but Twilio Node (node-red-node-twilio) allows one `To` phone number

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 November 2018 16:29 UTC](https://discourse.nodered.org/t/how-to-send-sms-to-different-number-using-twilio/5111/12 "2018-11-22T16:29:27Z")

</div>

From the Twilio node's readme " The node can be configured with the number to send the message to. Alternatively, if the number is left blank, it can be set using `msg.topic`."

---

<div class="post-metadata">

**Author:** ![Conard](https://avatars.discourse-cdn.com/v4/letter/c/41988e/32.png) [@Conard](https://discourse.nodered.org/u/Conard)\
**Post date:** [22 November 2018 16:38 UTC](https://discourse.nodered.org/t/how-to-send-sms-to-different-number-using-twilio/5111/13 "2018-11-22T16:38:05Z")

</div>

Yup, Colin. I read that too  
But I dont really understand what that means....  
Do I need another node to do it? Or just change the `To` field to `msg.Topic` in Twilio Node?

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [22 November 2018 16:39 UTC](https://discourse.nodered.org/t/how-to-send-sms-to-different-number-using-twilio/5111/14 "2018-11-22T16:39:56Z")

</div>

You leave the To entry in the node empty.

It then takes the value of msg.topic as the phone number.  
Try it with your own number...

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 November 2018 16:44 UTC](https://discourse.nodered.org/t/how-to-send-sms-to-different-number-using-twilio/5111/15 "2018-11-22T16:44:56Z")

</div>

You can use a change node between the db node and the twilio node configured to Move msg.payload[0].P\_Contact To msg.topic

---

<div class="post-metadata">

**Author:** ![Conard](https://avatars.discourse-cdn.com/v4/letter/c/41988e/32.png) [@Conard](https://discourse.nodered.org/u/Conard)\
**Post date:** [22 November 2018 16:48 UTC](https://discourse.nodered.org/t/how-to-send-sms-to-different-number-using-twilio/5111/16 "2018-11-22T16:48:15Z")

</div>

How can I generate`msg.Topic` value?

 ![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/ed11b71b6cc9f054968ba01d7d33c6c81abae13f.jpeg)

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [22 November 2018 16:50 UTC](https://discourse.nodered.org/t/how-to-send-sms-to-different-number-using-twilio/5111/17 "2018-11-22T16:50:41Z")

</div>

You can use a function node or a change node. But really if you need to ask that it would be worth stopping and doing one of the online tutorials to Node-RED.

---

<div class="post-metadata">

**Author:** ![Conard](https://avatars.discourse-cdn.com/v4/letter/c/41988e/32.png) [@Conard](https://discourse.nodered.org/u/Conard)\
**Post date:** [22 November 2018 17:06 UTC](https://discourse.nodered.org/t/how-to-send-sms-to-different-number-using-twilio/5111/18 "2018-11-22T17:06:08Z")

</div>

Is it correct? Change Node properties

 ![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/be0dc9bcdff435ce5bb32c320f3dcb51a62611ec.jpeg)

And I always get the error Connection is closed to MSSQL Node. I don't know why

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [22 November 2018 17:09 UTC](https://discourse.nodered.org/t/how-to-send-sms-to-different-number-using-twilio/5111/19 "2018-11-22T17:09:37Z")

</div>

Place debug nodes along your flow, so you can see what messages are being passed along and what they contain. Take time to read the documentation such as this page [https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)

But time on doing one of the tutorials would be time well spent...

---

<div class="post-metadata">

**Author:** ![Conard](https://avatars.discourse-cdn.com/v4/letter/c/41988e/32.png) [@Conard](https://discourse.nodered.org/u/Conard)\
**Post date:** [22 November 2018 17:44 UTC](https://discourse.nodered.org/t/how-to-send-sms-to-different-number-using-twilio/5111/20 "2018-11-22T17:44:02Z")

</div>

Ok. I have success received the SMS. But message body is empty? How can I edit the message content?

 ![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/2848b84e3e6adff4db77882ede70e523ad77a7d4.jpeg)

[Next page](https://discourse.nodered.org/t/how-to-send-sms-to-different-number-using-twilio/5111.md?page=2)
