Skip to content

Instantly share code, notes, and snippets.

Avatar
😅

Matthew Gilliard mjg123

😅
View GitHub Profile
@mjg123
mjg123 / KtTwilioTest.kt
Last active Apr 12, 2021
Kotlin code generating some TwiML
View KtTwilioTest.kt
import com.twilio.twiml.VoiceResponse
import com.twilio.twiml.voice.Pause
import com.twilio.twiml.voice.Record
import com.twilio.twiml.voice.Say
fun main(args: Array<String>){
val record = Record.Builder()
.timeout(8).transcribe(true)
.recordingStatusCallback("https://webhook.site/a6340ade-e239-4276-b488-67f4428c6cab")
View MessagingController.java
public String messageBuilder(Price price, String symbol) {
return String.format("Here are the most up-to-date %s prices:\n" +
"\uD83C\uDF05 Open price of the day: $%s\n" +
"\uD83D\uDCC8 High price of the day: $%s\n" +
"\uD83D\uDCC9 Low price of the day: $%s\n" +
"\uD83D\uDD14 Current price: $%s\n" +
"\uD83D\uDCC6 Previous close price: $%s\n" +
"\uD83E\uDD1E Send another symbol.",
symbol, price.open, price.high, price.low, price.current, price.close);
}
View SmsDemo.java
package com.twilio.demo;
import com.twilio.http.TwilioRestClient;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;
public class SmsDemo {
public static void main(String[] args) {
View SmsDemo.java
package com.twilio.demo;
import com.google.common.util.concurrent.ListenableFuture;
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;
public class SmsDemo {
public static void main(String[] args) {
View SmsDemo.java
package com.twilio.demo;
import com.google.common.util.concurrent.ListenableFuture;
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;
public class SmsDemo {
public static void main(String[] args) {
View ParseHttpBodyParams.java
// This method exists to work around a quirk in HttpServletRequest. For validation we only
// need to consider the parameters from the request *body*, but HSR.getParameterMap() *also* includes
// any parameters found in the query String, which will cause validation to fail.
// For POST requests, Twilio will not add any queryString params, but it's perfectly possible for a
// user to do that by including them in the webhook URL.
private HashMap<String, String> extractOnlyBodyParams(HttpServletRequest request, String validationUrl) throws IOException {
var allRequestParameters = request.getParameterMap();
var queryStringParams = UriComponentsBuilder.fromUriString(validationUrl).build().getQueryParams();
View RequestValidation.java
import com.twilio.security.RequestValidator;
import java.util.HashMap;
import static spark.Spark.get;
import static spark.Spark.post;
public class RequestValidation {
public static void main(String[] args) {
@mjg123
mjg123 / RequestValidation.java
Created Aug 18, 2020
Validating the X-Twilio-Signature header with SparkJava
View RequestValidation.java
import com.twilio.security.RequestValidator;
import java.util.HashMap;
import static spark.Spark.get;
import static spark.Spark.post;
public class RequestValidation {
public static void main(String[] args) {
View RequestValidation.java
import com.twilio.security.RequestValidator;
import java.util.HashMap;
import static spark.Spark.get;
import static spark.Spark.post;
public class RequestValidation {
public static void main(String[] args) {
@mjg123
mjg123 / GitHubAPITest.java
Created Aug 13, 2020
GH API extra changes
View GitHubAPITest.java
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.codec.binary.Base64;
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse.BodyHandlers;