I am attempting to implement a feature that allows a user to send an SMS to a mobile number from a web application using the Twilio API. The application setup consists of two text boxes: DestnationPhone.Text SmsMessage.Text In this feature, a user will enter the mobile phone number in the DestnationPhone text box and the message in the SmsMessage text box. After this, the user will click the send button to send the message to the recipient's mobile number. I would like guidance on how to achieve this using the Twilio API. Below is the code I have attempted, but I am encountering errors on two lines, and I am unsure if it is correct. Please see the code snippet in the image below for reference: Can someone provide assistance on how to properly implement this feature?
After weesk of trying , this is the new error I got:
Credetials have not been initialized or changed, please call TwilioClient.init()
This is my HTML and Code
HTML
<form id="form1" runat="server">
<div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<div class="input-group">
<asp:TextBox ID="DestinationNumber" placeholder="Mobile Number" Width="300px" Height="30px" CssClass="form-control" Font-Size="10pt" runat="server"></asp:TextBox>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<div class="input-group">
<asp:TextBox ID="SMSmessage" runat="server" AutoCompleteType="None" CssClass="form-control" placeholder="Your message" TextMode="MultiLine" Style="overflow: hidden; font-size: 10pt; resize: none;" oninput="Resize(this)" />
<script type="text/javascript">
function Resize(textbox) {
textbox.style.height = "";
textbox.style.height = Math.min(textbox.scrollHeight, 300) + "px";
}
</script>
</div>
</div>
</div>
</div>
<asp:Button ID="Button8" runat="server" Text="Button" CssClass="btn btn-primary" OnClick="Button8_Click" />
</div>
</form>
C#
{
// Get the Twilio credentials
string accountSid = "ACf3e50202f5988c915d37e995a62b51ec"; // Replace with your Account SID
string authToken = "166eb90fe50b38b7ba1bb4d841852ec8"; // Replace with your Auth Token
// Get the phone number and message text from the TextBox
string phoneNumber = DestinationNumber.Text;
string messageBody = SMSmessage.Text;
// Initialize the Twilio client
TwilioRestClient client = new TwilioRestClient(accountSid, authToken);
// Create a new SMS message
try
{
ITwilioRestClient twilioRestClient = null;
var message = MessageResource.Create(
to: new PhoneNumber("+15017122661"),
from: new PhoneNumber("+15017122661"),
body: "Hey there!",
// Here's where you inject the custom client
client: twilioRestClient
);
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message + "');</script>");
}
}