I am currently using the twilio trail account. I have integrated Twilio in azure(function app).
#r "Microsoft.Azure.ApiHub.Sdk"
#r "Newtonsoft.Json"
#r "System.Data"
#r "Twilio.Api"
using System;
using System.Configuration;
using System.Data.SqlClient;
using System.Data.Common;
using Microsoft.Azure.ApiHub;
using Newtonsoft.Json.Linq;
using Twilio;
public static void Run(TraceWriter log, out SMSMessage smsmessage)
{
smsmessage = new SMSMessage();
string phonenumber = "";
string MessageBody = "sample message";
using (SqlConnection conn = new SqlConnection(str))
{
conn.Open();
var sqlStr = "SELECT [phone] FROM [dbo].[tbl_ContactTable] where [ID] = 2"; //It returns two rows with twilio verified phone numbers
using (SqlCommand cmd = new SqlCommand(sqlStr, conn))
{
var dataReader = cmd.ExecuteReader();
if(dataReader.HasRows)
{
while(dataReader.Read())
{
phonenumber = dataReader[0].ToString();
log.Info($" phonenumber {phonenumber}");
smsmessage.Body = MessageBody;
smsmessage.To = phonenumber;
}
}
dataReader.Close();
}
conn.Close();
}}
Two phone numbers are shown in the log, but a message is sent only to the last phone number(phone number present in the last row). Is there any way to iterate through phone numbers to send the message to multiple numbers at once.