All Projects → vapor-community → VaporTwilioService

vapor-community / VaporTwilioService

Licence: other
Twilio API provider for all your Vapor needs

Programming Languages

swift
15916 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to VaporTwilioService

Vaporsecurityheaders
Harden Your Security Headers For Vapor
Stars: ✭ 107 (+463.16%)
Mutual labels:  vapor, server-side-swift
Mistkit
Swift Package for Server-Side and Command-Line Access to CloudKit Web Services
Stars: ✭ 129 (+578.95%)
Mutual labels:  vapor, server-side-swift
Sql Kit
*️⃣ Build SQL queries in Swift. Extensible, protocol-based design that supports DQL, DML, and DDL.
Stars: ✭ 115 (+505.26%)
Mutual labels:  vapor, server-side-swift
Aws
Swift wrapper around AWS API
Stars: ✭ 67 (+252.63%)
Mutual labels:  vapor, server-side-swift
Http
🚀 Non-blocking, event-driven HTTP built on Swift NIO.
Stars: ✭ 220 (+1057.89%)
Mutual labels:  vapor, server-side-swift
Vapor Clean
A Vapor 3 template with no additional cruft.
Stars: ✭ 80 (+321.05%)
Mutual labels:  vapor, server-side-swift
Flock
Automated deployment of Swift projects to servers
Stars: ✭ 127 (+568.42%)
Mutual labels:  vapor, server-side-swift
Admin Panel Provider
Build easy customizable admin features for your app ✍️
Stars: ✭ 47 (+147.37%)
Mutual labels:  vapor, server-side-swift
Mysql Kit
🐬 Pure Swift MySQL client built on non-blocking, event-driven sockets.
Stars: ✭ 159 (+736.84%)
Mutual labels:  vapor, server-side-swift
Websocket Kit
WebSocket client library built on SwiftNIO
Stars: ✭ 155 (+715.79%)
Mutual labels:  vapor, server-side-swift
Core
🌎 Utility package containing tools for byte manipulation, Codable, OS APIs, and debugging.
Stars: ✭ 62 (+226.32%)
Mutual labels:  vapor, server-side-swift
Telegrammer
Telegram Bot - written with Swift 5.2 / NIO, supports Linux, macOS
Stars: ✭ 248 (+1205.26%)
Mutual labels:  vapor, server-side-swift
Fluent
Vapor ORM (queries, models, and relations) for NoSQL and SQL databases
Stars: ✭ 1,071 (+5536.84%)
Mutual labels:  vapor, server-side-swift
Vapor Oauth
OAuth2 Provider Library for Vapor
Stars: ✭ 90 (+373.68%)
Mutual labels:  vapor, server-side-swift
Fluent Sqlite Driver
Fluent driver for SQLite
Stars: ✭ 51 (+168.42%)
Mutual labels:  vapor, server-side-swift
Open Crypto
🔑 Hashing (BCrypt, SHA2, HMAC), encryption (AES), public-key (RSA), and random data generation.
Stars: ✭ 115 (+505.26%)
Mutual labels:  vapor, server-side-swift
Apicore
Core API functionality (users & teams, passwords, emails, etc) for any service built with Vapor 3
Stars: ✭ 43 (+126.32%)
Mutual labels:  vapor, server-side-swift
Leaf Error Middleware
Serve up custom 404 and server error pages for your Vapor App
Stars: ✭ 43 (+126.32%)
Mutual labels:  vapor, server-side-swift
Api Template
💧 A starting point for Vapor APIs.
Stars: ✭ 130 (+584.21%)
Mutual labels:  vapor, server-side-swift
Htmlkit
A type-safe DSL that renders dynamic HTML templates in Swift
Stars: ✭ 229 (+1105.26%)
Mutual labels:  vapor, server-side-swift
Documentation Team Chat MIT License Continuous Integration

Github Actions

Swift 5.1

What

This is a wrapper service for interacting with the Twilio API for Vapor4

Note: Vapor3 version is available in vapor3 branch and from 1.0.0 tag

Installation

// dependencies
.package(url: "https://github.com/twof/VaporTwilioService.git", from: "2.0.0")

// Targets
.target(name: "App", dependencies: [
    .product(name: "Vapor", package: "vapor"),
    .product(name: "Twilio", package: "VaporTwilioService")
])

Usage

Setup

import Twilio

// Called before your application initializes.
func configure(_ app: Application) throws {
    /// case 1
    /// put into your environment variables the following keys:
    /// TWILIO_ACCOUNT_ID=...
    /// TWILIO_ACCOUNT_SECRET=...
    app.twilio.configuration = .environment

    /// case 2
    /// manually
    app.twilio.configuration = .init(accountId: "<account id>", accountSecret: "<account secret>")
}

Sending a text

In route handler

import Twilio

func routes(_ app: Application) throws {
    app.get { req -> EventLoopFuture<ClientResponse> in
        let sms = OutgoingSMS(body: "Hey There", from: "+18316100806", to: "+14083688346")
        return req.twilio.send(sms)
    }
}

Anywhere else

import Twilio

public func configure(_ app: Application) throws {
    // ...
    // e.g. in the very end
    let sms = OutgoingSMS(body: "Hey There", from: "+18316100806", to: "+14083688346")
    app.twilio.send(sms).whenSuccess { response in
        print("just sent: \(response)")
    }
}

Handling Incoming Texts

After setting up the necessary routing within your Twilio account, you may create routes to handle and respond to incoming texts.

import Twilio

func routes(_ app: Application) throws {
    app.post("incoming") { req -> Response in
        let sms = try req.content.decode(IncomingSMS.self)

        let responseMessage = SMSResponse(
            Message(body: "Hello Friend!"),
            Message(body: "This is a second text.")
        )

        return req.twilio.respond(with: responseMessage)
    }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].