Matthew Raymer
1 year ago
3 changed files with 48 additions and 6 deletions
@ -0,0 +1,34 @@ |
|||||
|
from pywebpush import webpush, WebPushException |
||||
|
|
||||
|
import json |
||||
|
|
||||
|
# these below will only work for the browser that acquired the subscription info. You will need to extract those from our console OR the db. |
||||
|
|
||||
|
# https://fcm.googleapis.com/fcm/send/e5jo1pnUZPA:APA91bEwHV2DeLybHc23G_-zJ4FXIdK_fh16ANVOrBekDeKNdmvZ0ukkPXsYGvq629KR2_ZK2w6rQHwC6hkbZ6Xqg0HktarvFT7wTQPjq7bkLgqqjOoONYZDPriDd9DvkD2vamzrPoBx |
||||
|
# BCj38CJs7M9rXDnZLBVU-XHYrAIdqCuTdscC_Waj96Z2KcMuTHI46kKssjmNwdkIae3Plr__UXbisdC5YPsIeFA |
||||
|
# 8cyYFZDqjGiZ4nBMfa2L8Q |
||||
|
|
||||
|
# MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgrIaKlYimnslibbhXyq5CsNZUKIq/c7DY8aa0P/8JNQihRANCAARm2kU8Hnk9fiGrY7M06A+WcVqpfleGObX+gJL4dS+m4fkYIySEbHC/GjSAQRunh+ZSvoBJo2oUKUaB90XExMT3 |
||||
|
|
||||
|
subscription_info = { |
||||
|
"endpoint": "https://fcm.googleapis.com/fcm/send/e5jo1pnUZPA:APA91bEwHV2DeLybHc23G_-zJ4FXIdK_fh16ANVOrBekDeKNdmvZ0ukkPXsYGvq629KR2_ZK2w6rQHwC6hkbZ6Xqg0HktarvFT7wTQPjq7bkLgqqjOoONYZDPriDd9DvkD2vamzrPoBx", |
||||
|
"keys": { |
||||
|
"p256dh": "BCj38CJs7M9rXDnZLBVU-XHYrAIdqCuTdscC_Waj96Z2KcMuTHI46kKssjmNwdkIae3Plr__UXbisdC5YPsIeFA", |
||||
|
"auth": "8cyYFZDqjGiZ4nBMfa2L8Q" |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
data = json.dumps({"title": "test", "message": "here is a message"}) |
||||
|
|
||||
|
try: |
||||
|
webpush(subscription_info, |
||||
|
data, |
||||
|
# vapid_private_key="./private_key.pem", |
||||
|
vapid_private_key="MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgrIaKlYimnslibbhXyq5CsNZUKIq/c7DY8aa0P/8JNQihRANCAARm2kU8Hnk9fiGrY7M06A+WcVqpfleGObX+gJL4dS+m4fkYIySEbHC/GjSAQRunh+ZSvoBJo2oUKUaB90XExMT3", |
||||
|
vapid_claims={"sub": "mailto:matthew.raymer@gmail.com"}) |
||||
|
except WebPushException as ex: |
||||
|
print(f"An error occurred: {ex}") |
||||
|
# Check if there is a response from the remote service. |
||||
|
if ex.response: |
||||
|
response_data = ex.response.json() |
||||
|
print(f"Response from remote service: {response_data}") |
Loading…
Reference in new issue