Reputation: 35
i am sending sms on mobile through plivo and then user will reply me by yes or No to receive sms on my plivo. Now i have make class in c# and put this code
using System;
using System.Collections.Generic;
using System.Reflection;
using Nancy;
using RestSharp;
using Plivo.API;
namespace Receive_Sms
{
public class Program : NancyModule
{
public Program()
{
Post["/receive_sms"] = x =>
{
String from_number = Request.Form["From"]; // Sender's phone number
String to_number = Request.Form["To"]; // Receiver's phone number
String text = Request.Form["Text"]; // The text which was received
// Print the message
Console.WriteLine("Message received - From: {0}, To: {1}, Text: {2}", from_number, to_number, text);
return "Message received";
};
}
}
}
can i use this code in webservice.asmx if yes how? how do i test this code? while creating application in message url what i write in after server url class name or method name? e.g. http://example.com/receive_sms
Upvotes: 1
Views: 1180
Reputation: 866
Try this :
Create .aspx page named reply_to_sms.aspx and paste this code in page load function
String from_number = Request.Form["From"]; // Sender's phone number
String to_number = Request.Form["To"]; // Receiver's phone number
String text = Request.Form["Text"]; // The text which was received
After that create a mail function to send these data to email or insert these values in database
add application on server by using this link [https://www.plivo.com/docs/sms/getting-started/basic/receive-an-sms/]
Note : you can only check if your page has online link like : abc.com/reply_to_sms.aspx
Upvotes: 1
Reputation: 409
To receive messages on your Plivo number, you will have to configure the "Message URL" of the Plivo Application attached to that number. Steps to create a Plivo application are here and steps to attach that application to your Plivo number are here.
Next, you'll have to host your code publicly so that Plivo can send requests to your .Net application. You could use platforms like Microsoft Azure or Appharbor to host your .Net code. After deployment, use your hosted application URL (like https://yourapp.appharbor.com/receive_sms) to configure the Message URL in your Plivo Application created in the previous step.
"Post["/receive_sms"]" - This line in your code defines the route for you application. The URL that has to be configured as your Message URL would be https://yourapp.domain/receive_sms. More details about routing in Nancy Framework here.
To reply to incoming messages, your Message URL should return a Message XML. You can find these instructions here. More details about Message XML here.
Upvotes: 1