GatewayAPI is a Vapor helper for using GatewayAPIKit to send text messages (SMS) to mobile phones.
GatewayAPI is installed using Swift Package Manager, please modify your Package.swift to include the following code:
dependencies: [
...
.package(url: "https://github.com/vapor-community/gatewayapi.git", from: "1.0.0-rc.1")
],
...
targets: [
.target(
name: ...
dependencies: [
...
.product(name: "GatewayAPI", package: "gatewayapi")
]
)
]Make you sure you create an account over at GatewayAPI
In your configure.swift add one of the following configuration options:
import GatewayAPI
func configure(_ app: Application) throws {
// Option 1: Use environment variable GATEWAYAPI_APIKEY
app.gatewayAPI.configuration = .environment
// Option 2: Manual config
app.gatewayAPI.configuration = .init(apiKey: "api_key")
}You can use the API client either through Application or Request
import GatewayAPI
func configure(_ app: Application) throws {
app.gatewayAPI.configuration = .environment
_ = app.gatewayAPI.client.send("Text message": to: ["4510203040"], from: "Mads")
}import GatewayAPI
func sendSMS(req: Request) throws -> EventLoopFuture<Void> {
return req.gatewayAPI.send("Text message": to: ["4510203040"], from: "Mads").transform(to: ())
}