Skip to content

Handling Incoming Texts

Compare
Choose a tag to compare
@twof twof released this 11 Jan 02:08
· 23 commits to master since this release
c932d51

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)
}