Swiftpack.co - Package - twof/VaporTwilioService
Documentation Team Chat MIT License Continuous Integration Swift 4.1

What

This is a wrapper service for interacting with the Twilio API

Installation

  // dependencies
 .package(url: "https://github.com/twof/VaporTwilioService.git", from: "1.0.0")
 
  // Targets
  .target(name: "App", dependencies: ["Twilio"])

Usage

Setup

// Setup
guard let accountId = Environment.get("TWILIO_ACCOUNT_ID") else { fatalError() }
guard let accountSecret = Environment.get("TWILIO_ACCOUNT_SECRET") else { fatalError() }
let twilio = Twilio(accountId: accountId, accountSecret: accountSecret)

services.register(twilio)

Sending a text

let twilio = try req.make(Twilio.self)

let sms = OutgoingSMS(body: "Hey There", from: "+15556100806", to: "+15553688346")

return try twilio.send(sms, on: req)

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

Github

link
Stars: 3
Help us keep the lights on

Dependencies

Used By

Total: 0

Releases

1.1.1 - Jan 19, 2019

The target names being used for the example app were clashing with folks projects. Should be fine now.

1.1.0 - Jan 11, 2019

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

1.0.1 - Jan 9, 2019

Thanks to @mergesort for pointing out the Mailgun reference

1.0.0 - Jan 9, 2019

This one supports sending texts