Home > front end >  Twilio Incoming Message
Twilio Incoming Message

Time:03-21

I am unable to get the incoming message, and my response is not being sent back to the person

I have the following set up in SmsController

using System;
using System.Net.Mail;
using System.Configuration;
using System.Web.Mvc;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;
using Twilio.AspNet.Common;
using Twilio.TwiML;
using Twilio.AspNet.Mvc;
using Chat.Models;


public class SmsController : TwilioController
{
[HttpPost]
public TwiMLResult ReceiveSms(SmsRequest incomingMessage)
{
    try
    {
        Applicant applicant = new Applicant();
        string Phone = incomingMessage.From;
        string UserID = applicant.GetUserIDByTelephone(Phone);
        string MgrName = applicant.GetMessageSender(UserID);
        string ApplicantName = applicant.GetName(UserID);

        //Get the Message and the MessageID
        string Body = incomingMessage.Body;
        string MessageSid = incomingMessage.SmsSid;

        //Save incoming message in the database
        applicant.IncomingMessage(UserID, Body, MessageSid);

        //Send applicant a message acknowledging that the text was received.
        var response = new MessagingResponse();
        response.Message("Thank you for your response.  We will respond to your message shortly.");

        //Get information on the manager
        Manager manager = new Manager();
        string MgrID = manager.GetMgrID(MgrName);
        string email = manager.GetMgrEmail(MgrID);
        bool notify = manager.Notify(MgrID);

        //Send the email notification if manager set to receive notification.
        if (notify)
        {
            SendEmail(email, ApplicantName, Body);
        }
        return TwiML(response);
    }
    catch (Exception ex)
    {
        Errors.ErrorOccured(ex,"message sent = "   incomingMessage.Body);
        MessagingResponse messagingResponse = new MessagingResponse();
        messagingResponse.Message("oops.. An error has occured.");
        return TwiML(messagingResponse);
    }
}
}

I have the Webhook set in Twilio

https://www.myUrl/admin/applicantmanagement/Sms/ReceiveSms

The above is the address for this particular MVC APP.

Yet I am not receiving the response from the user

So that was when I added the try catch as this line is set to send me an email on any errors that occur in the model or controller

Errors.ErrorOccured(ex,"message sent = "   incomingMessage.Body);

The Twilio documentation does not show it like this but I also have my SendSms ActionResult in the same controller, could that be my issue?

CodePudding user response:

I had a bad url. The app was placed in a virtual directory called sms so the actual webhook should have benn

https://www.myUrl/admin/applicantmanagement/sms/Sms/ReceiveSms
  • Related