-
-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add apnotic for iOS notifications (#163)
* Add apnotic for iOS notifications * Standardize * APNS updates (#165) * Fix namespace typo * Fix typo * Fail if response isn't 200 * Set topic (bundle identifier) * Use development vs. production APNS servers * Configurable iOS credentials * Move delivery method docs to docs folder Co-authored-by: Joe Masilotti <[email protected]>
- Loading branch information
1 parent
d52aa7b
commit 0791277
Showing
13 changed files
with
408 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
### ActionCable Delivery Method | ||
|
||
Sends a notification to the browser via websockets (ActionCable channel by default). | ||
|
||
`deliver_by :action_cable` | ||
|
||
##### Options | ||
|
||
* `format: :format_for_action_cable` - *Optional* | ||
|
||
Use a custom method to define the Hash sent through ActionCable | ||
|
||
* `channel` - *Optional* | ||
|
||
Override the ActionCable channel used to send notifications. | ||
|
||
Defaults to `Noticed::NotificationChannel` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
### Database Delivery Method | ||
|
||
Writes notification to the database. | ||
|
||
`deliver_by :database` | ||
|
||
**Note:** Database notifications are special in that they will run before the other delivery methods. We do this so you can reference the database record ID in other delivery methods. For that same reason, the delivery can't be delayed (via the `delay` option) or an error will be raised. | ||
|
||
##### Options | ||
|
||
* `association` - *Optional* | ||
|
||
The name of the database association to use. Defaults to `:notifications` | ||
|
||
* `format: :format_for_database` - *Optional* | ||
|
||
Use a custom method to define the attributes saved to the database | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
### Email Delivery Method | ||
|
||
Sends an email notification. Emails will always be sent with `deliver_later` | ||
|
||
`deliver_by :email, mailer: "UserMailer"` | ||
|
||
##### Options | ||
|
||
* `mailer` - **Required** | ||
|
||
The mailer that should send the email | ||
|
||
* `method: :invoice_paid` - *Optional* | ||
|
||
Used to customize the method on the mailer that is called | ||
|
||
* `format: :format_for_email` - *Optional* | ||
|
||
Use a custom method to define the params sent to the mailer. `recipient` will be merged into the params. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# iOS Notification Delivery Method | ||
|
||
Send Apple Push Notifications with HTTP2 using the `apnotic` gem. The benefit of HTTP2 is that we can receive feedback for invalid device tokens without running a separate feedback service like RPush does. | ||
|
||
```bash | ||
bundle add "apnotic" | ||
``` | ||
|
||
## Usage | ||
|
||
```ruby | ||
class CommentNotification | ||
deliver_by :ios | ||
end | ||
``` | ||
|
||
With custom configuration: | ||
|
||
```ruby | ||
class CommentNotification | ||
deliver_by :ios, format: :ios_format, cert_path: :ios_cert_path, key_id: :ios_key_id, team_id: :ios_team_id, pool_size: 5 | ||
|
||
# Customize notification | ||
# See https://github.com/ostinelli/apnotic#apnoticnotification | ||
def ios_format(apn) | ||
apn.alert = "Hello world" | ||
apn.custom_payload = { url: root_url } | ||
end | ||
|
||
def ios_cert_path | ||
Rails.root.join("config/certs/ios/apns.p8") | ||
end | ||
|
||
def ios_key_id | ||
Rails.application.credentials.dig(:ios, :key_id) | ||
end | ||
|
||
def ios_team_id | ||
Rails.application.credentials.dig(:ios, :team_id) | ||
end | ||
end | ||
``` | ||
|
||
## Options | ||
|
||
* `format: :ios_format` - *Optional* | ||
|
||
Customize the Apnotic notification object | ||
|
||
See https://github.com/ostinelli/apnotic#apnoticnotification | ||
|
||
* `bundle_identifier: Rails.application.credentials.dig(:ios, :bundle_identifier)` - *Optional* | ||
|
||
The APN bundle identifier | ||
|
||
* `cert_path: Rails.root.join("config/certs/ios/apns.p8")` - *Optional* | ||
|
||
The location of your APNs p8 certificate | ||
|
||
* `key_id: Rails.application.credentials.dig(:ios, :key_id)` - *Optional* | ||
|
||
Your APN Key ID | ||
|
||
If nothing passed, we'll default to `Rails.application.credentials.dig(:ios, :key_id)` | ||
If a String is passed, we'll use that as the key ID. | ||
If a Symbol is passed, we'll call the matching method and you can return the Key ID. | ||
|
||
* `team_id: Rails.application.credentials.dig(:ios, :team_id)` - *Optional* | ||
|
||
Your APN Team ID | ||
|
||
If nothing passed, we'll default to `Rails.application.credentials.dig(:ios, :team_id)` | ||
If a String is passed, we'll use that as the team ID. | ||
If a Symbol is passed, we'll call the matching method and you can return the team ID. | ||
|
||
* `pool_size: 5` - *Optional* | ||
|
||
The connection pool size for Apnotic | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
### Microsoft Teams Delivery Method | ||
|
||
Sends a Teams notification via webhook. | ||
|
||
`deliver_by :microsoft_teams` | ||
|
||
#### Options | ||
|
||
* `format: :format_for_teams` - *Optional* | ||
|
||
Use a custom method to define the payload sent to Microsoft Teams. Method should return a Hash. | ||
Documentation for posting via Webhooks available at: https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook | ||
|
||
```ruby | ||
{ | ||
title: "This is the title for the card", | ||
text: "This is the body text for the card", | ||
sections: [{activityTitle: "Section Title", activityText: "Section Text"}], | ||
"potentialAction": [{ | ||
"@type": "OpenUri", | ||
name: "Button Text", | ||
targets: [{ | ||
os: "default", | ||
uri: "https://example.com/foo/action" | ||
}] | ||
}] | ||
|
||
} | ||
``` | ||
|
||
* `url: :url_for_teams_channel`: - *Optional* | ||
|
||
Use a custom method to retrieve the MS Teams Webhook URL. Method should return a string. | ||
|
||
Defaults to `Rails.application.credentials.microsoft_teams[:notification_url]` | ||
|
||
|
Oops, something went wrong.