How to process incoming sms using Twilio - java

I am using Twilio for sending SMS from my Java Web Application. I have a Twilio number purchased under my account. Now I am trying to process the incoming SMS to my Twilio number. All I am trying to do is to pass the message data and the sender of the message as an HTTP GET method to my application. I have found the following under my account settings:
In my application, I can add a REST service that can accept these details and save the required details to my database. But I am unable to find any example related to this. Is there any way to get the message details whenever a message is received.

Twilio makes HTTP requests to your application just like a regular web
browser. By including parameters and values in its requests, Twilio
sends data to your application that you can act upon before
responding.
https://www.twilio.com/docs/api/twiml/sms/twilio_request#twilio-data-passing
When Twilio receives a message for one of your Twilio numbers it makes a synchronous HTTP request to the message URL configured for that number, and expects to receive TwiML in response.
Twilio sends parameters with its request as POST parameters or URL query parameters, depending on which HTTP method you've configured. https://www.twilio.com/docs/api/twiml/sms/twilio_request#request-parameters
If you are using Spring MVC annotations, you can add an annotated parameter to your method's parameters:
#RequestMapping(
value = "/someEndPoint",
method = RequestMethod.POST,
consumes = "text/plain"
)
public String someMethod(#RequestParam("param1") String paramOne) {
//use paramOne variable here
}

Related

I don't get push notifications from google drive api

I followed this guide
For local testing and webhook processing, I used https://webhook.site
I managed to get messages about file changes (google sheets)
Next, I tried to configure the local endpoint of my application to handle the webhook
From the documentation https://support.google.com/googleapi/answer/7072069?hl=en
An address property string set to the URL that listens and responds to
notifications for this notification channel. This is your Webhook
callback URL, and it must use HTTPS.
Also for local testing I used https://ngrok.com/
#PostMapping("/notifications")
#AnonymousAllowed
public ResponseEntity<Void> webHookHandler(HttpServletRequest request) {
String headerGoogChanged = request.getHeader("x-goog-changed");
if (!ObjectUtils.isEmpty(headerGoogChanged) && headerGoogChanged.contains("content")) {
service.parseDashboardAndSave(view.getGrid(), sheetsService.readSheetValuesBatch());
sheetsService.writeSheetValuesBatch(service.getKeyWordDashboards());
log.info("Push notification processed: {}", request);
}
return ResponseEntity.ok().build();
}
But I don't get push notifications
At the same time, calling endpoints https://localhost:8080/notifications and https://xxxxxxeu.ngrok.io/notifications through postman will work
I heard that you need to pass domain verification and also have an SSL certificate
I found that now there is no need to confirm the domain in this documentation

How can we perform 2 get request at same time Rest assured API Testing

JAVA RESTASSURED APITESTNG CUCUMBER
when I send get request using path variable and query param, I get a token in the response body and I will not get proper response until I add that token as a query param and send another get request.
So How can I perform that?
Given Cucumber Feature File
Given API has the following filed <"fieldName">
When API sends a "GET" request to "TranscationAPI"
Then API will receive the response code as 200
And the body will have following field
Should I change it to something like this?
Given API has the following filed <"fieldName">
When API sends a "GET" request to "TranscationAPI"
Then API will receive token as ""
When API sends again "GET" request to "TranscationAPI"
Then API will receive the response code as 200
And the body will have following field
Or I can use handle this through a different method.
Background is the great place to obtain token - see https://cucumber.io/docs/gherkin/reference/#background
It's possible by Java multithreading mechanism - https://www.tutorialspoint.com/java/java_multithreading.htm

Not Able to create Subscription to mailbox using Microsoft graph API

Getting Subscription validation failed.Must respond with 200 OK error
I was trying to create a subscription using Microsoft graph API. We have exposed a notification URL which on receiving the post-call from the graph API will respond with the validation token and also status code: 200 OK.
When I tried hitting the subscription API for creating subscription it is showing "Getting Subscription validation failed. Must respond with 200 OK"-error. And At the same time, we are getting Status: 400 Bad request in postman.
Microsoft Graph validates the notification endpoint provided in the notificationUrl property of the subscription request before creating the subscription.
If validation fails, the request to create the subscription returns a 400 Bad Request error.
Please make sure that you provide a valid notificationUrl in the body. See Notification endpoint validation to see how Microsoft Graph handles the validation process.

How to send body as a Json in RestTemplate to get data from API [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
HTTP GET with request body
I've read few discussions here which do not advocate sending content via HTTP GET. There are restrictions on the size of data that can be sent via clients (web browsers). And handling GET data also depends on servers. Please refer section Resources below.
However, I've been asked to test the possibility to send content via HTTP GET using RestTemplate. I refered few discussions on spring forum but they were not answered. (Please note sending data via http Post works fine). The discussion here suggests using POST instead.
dev env - JBoss AS 5.1, Spring 3.1.3
Client
#Test
public void testGetWithBody()
{
// acceptable media type
List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
acceptableMediaTypes.add(MediaType.TEXT_PLAIN);
// header
HttpHeaders headers = new HttpHeaders();
headers.setAccept(acceptableMediaTypes);
// body
String body = "hello world";
HttpEntity<String> entity = new HttpEntity<String>(body, headers);
Map<String, Object> uriVariables = new HashMap<String, Object>();
uriVariables.put("id", "testFile");
// Send the request as GET
ResponseEntity<String> result = restTemplate.exchange(
"http://localhost:8080/WebApp/test/{id}/body",
HttpMethod.GET, entity, String.class, uriVariables);
Assert.assertNotNull(result.getBody());
}
Server #Controller
#RequestMapping(value = "/{id}/body", method = RequestMethod.GET)
public #ResponseBody
String testGetWithBody(#PathVariable String id,
#RequestBody String bodyContent)
{
return id + bodyContent;
}
The problem -
executing this test case returns 500 Internal Server Error. On debugging, I found that the controller is not hit.
Is it correct to understand that the RestTemplate provides the way to send data as request body, but the error occurs because the server could not handle the request body ?
If the request body sent via HTTP Get is not conventional why does RestTemplate provide the APIs to allow sending it ? Does this mean there are few servers capable of handling the Request body via GET ?
Resources - discussions on sending body via HTTP GET using RestTemplate at spring forum
http://forum.springsource.org/showthread.php?129510-Message-body-with-HTTP-GET&highlight=resttemplate+http+get
http://forum.springsource.org/showthread.php?94201-GET-method-on-RestTemplate-exchange-with-a-Body&highlight=resttemplate+http+get
Resources - General discussions on sending body via HTTP GET
get-with-request-body
is-this-statement-correct-http-get-method-always-has-no-message-body
get-or-post-when-reading-request-body
http-uri-get-limit
Is it correct to understand that the RestTemplate provides the way to send data as request body, but the error occurs because the server could not handle the request body ?
You can tell by looking at network traffic (does the request get sent with a request body and a GET method?) and at server logs (the 500 result you receive must have a server-side effect that gets logged, and if not, configure the server to do so).
If the request body sent via HTTP Get is not conventional why does RestTemplate provide the APIs to allow sending it ? Does this mean there are few servers capable of handling the Request body via GET ?
Because it is a generic class that also allows you to craft requests that can include a message body.
As stated in HTTP GET with request body:
In other words, any HTTP request message is allowed to contain a message body, and thus [a server] must parse messages with that in mind. Server semantics for GET, however, are restricted such that a body, if any, has no semantic meaning to the request. The requirements on parsing are separate from the requirements on method semantics.
A body on a GET cannot do anything semantically, because you are requesting a resource. It's like you tell the server: "Give me resource X, oh, and have some apples!". The server won't care about your apples and happily serve resource X - or throw an error because it doesn't like any offers in a request.
However, I've been asked to test the possibility to send content via HTTP GET
Please tell the one who requested this that this is a case that should not have to be tested, because no sensible implementation supports it.

How to make java Method Class for sms gateway use HTTP protocol for communication beetween data

This is about sms gateway for enterprise. We'll Have 3 vendor sms gateway. I want to make method class that can send sms use url from each vendor. can you tell me how to make a method class as example follows:
void sendSmsToXXX (String phonenumber, String message) {
// Send to XXX, which is xxx is one of three sms gateway vendor.
}
For send HTTP GET requests in java we can using HttpURLConnection class. Then one of 3 vendor message require messages to be encoded hearts hexa Decimal, please use DatatypeConverter class.
and I have make a simulator at IP 10.213.5.86 ip port simulator in 8085.
for Example URL and parameter request is:
http://10.213.5.86:8085/sms/send/jatis?userid=JATIS&password=JATISabcd&msisdn=62857712345&message=tes kirim http GET&sender=SENDERJATIS&division=Marketing&batchname=test&uploadby=rangga&channel=2

Categories