import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.resource.instance.Sms;

import java.util.HashMap;
import java.util.Map;

import static spark.Spark.get;
import static spark.Spark.post;

public class SMSBackend {
    public static void main(String[] args) {
        get("/", (req, res) -> "Hello, World");

        TwilioRestClient client = new TwilioRestClient(System.getenv("TWILIO_ACCOUNT_SID"), System.getenv("TWILIO_AUTH_TOKEN"));

        post("/sms", (req, res) -> {
            String body = req.queryParams("Body");
            String to = req.queryParams("To");
            String from = System.getenv("TWILIO_NUMBER");

            Map<String, String> callParams = new HashMap<>();
            callParams.put("To", to);
            callParams.put("From", from);
            callParams.put("Body", body);
            Sms message = client.getAccount().getSmsFactory().create(callParams);

            return message.getSid();
        });
    }
}

@@ -77,16 +77,36 @@
 nce.Sms;
+%0Aimport spark.Spark;
 %0A%0Aimport
@@ -210,16 +210,51 @@
 rk.post;
+%0Aimport static spark.Spark.setPort;
 %0A%0Apublic
@@ -317,16 +317,385 @@
  args) %7B
+%0A%0A        //Heroku assigns different port each time, hence reading it from process.%0A        ProcessBuilder process = new ProcessBuilder();%0A        Integer port;%0A        if (process.environment().get(%22PORT%22) != null) %7B%0A            port = Integer.parseInt(process.environment().get(%22PORT%22));%0A        %7D else %7B%0A            port = 4567;%0A        %7D%0A        Spark.port(port);%0A%0A
 %0A       
@@ -1376,16 +1376,17 @@
     %7D);%0A
+%0A
     %7D%0A%7D%0A

Add heroku settings