Handling Incoming Texts
Handling Incoming Texts
After setting up the necessary routing within your Twilio account, you may create routes to handle and respond to incoming texts.
router.post("incoming") { (req) -> Response in
// This object will give you access to all of the properties of incoming texts
let sms = try req.content.syncDecode(IncomingSMS.self)
let twilio = try req.make(Twilio.self)
// You may respond with as many texts as you'd like
let responseMessage = SMSResponse(
Message(body: "Hello Friend!"),
Message(body: "This is a second text.")
)
return twilio.respond(with: responseMessage, on: req)
}