-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
34 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
##################################################################################### | ||
##################################################################################### | ||
#第一引数のclientにはcurrent_user.idとかでユーザーモデルを検索した結果のActiveRecordsを | ||
#第二引数のbodyには{name: "hoge"}みたいな形でjsonっぽく書いた文字列を渡してください | ||
##################################################################################### | ||
##################################################################################### | ||
|
||
def notification(client, body) | ||
payload = { | ||
endpoint: client.endpoint, # ブラウザでregistration.pushManager.getSubscription()で取得したsubscriptionのendpoint | ||
p256dh: client.key, # 同じくsubscriptionのp256dh | ||
auth: client.auth, # 同じくsubscriptionのauth | ||
ttl: 86400, # 任意の値 | ||
vapid: { | ||
subject: 'https://task-driver.sukiyaki.party', # APPサーバのコンタクト用URIとか('mailto:' もしくは 'https://') | ||
public_key: ENV['VAPID_PUBLIC_KEY'], | ||
private_key: ENV['VAPID_SECRET_KEY'] | ||
}, | ||
message: { | ||
title: "task", | ||
body: body | ||
}.to_json | ||
} | ||
Webpush.payload_send(payload) #送信 | ||
end |
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