This is a tiny library that allows you to send push messages using the OneSignal.com service.
The library is really simple, you pass it the app_id (or list of app_ids) and the API key, and you are done!
from pbsonesignal import PybossaOneSignal
client = PybossaOneSignal(api_key="yourkey", app_id="ID")
client.push_msg(contents={"en": "Your message in English", "es": "Tu mensaje en Español"})
In the case that you want to create a new app, just do the following:
from pbsonesignal import PybossaOneSignal
client = PybossaOneSignal(auth_key="yourkey")
client.create_app('name', 'https://yoursite.com', 'https://yoursite.com/icon')
The following is a list of all the arguments you can use with this client:
This is a dictionary that allows you send a message in different languages:
contents = {"en": "Your message in English", "es": "Tu mensaje en Español"}
Add as many languages as you want.
This is a dictionary that allows you send a heading in different languages:
headings = {"en": "Your heading in English", "es": "Tu título en Español"}
Add as many languages as you want.
This is a string with the url that should be launched when the user clicks (or touches) the notification.
url = "http://yoursite.com"
This is an array of dictionaries where you can add buttons to your notifications.
web_buttons=[{"id": "read-more-button",
"text": "Read more",
"icon": "http://i.imgur.com/MIxJp1L.png",
"url": "https://yoursite.com"}],
This is a string with the full URL to an image that you want to show in the body of the notification.
chrome_web_image="https://yourimage.com",
This is a string with the full URL to an icon that you want to show in the notification.
chrome_web_icon="https://yourimage.com",
This is a list of string. It lists all the segments you will be sending the notification. By default is All.
included_segments=["All"],
This is a list of string. It lists all the segments you will not be sending the notification. By default is empty.
excluded_sements=[],
This is a list of dictionaries. It allows you to filter your segments. By default is empty.
filters=[],
This is a list of strings. Specify player IDs to only send the notifications to them. By default is None, so it will be sent to all the users.
include_player_ids=None
This is a string. Specify a date and time to send the notification. By default is None, so it will be sent immediately.
send_after=None
This is a string. Specify when it has be delayed. By default is None.
delayed_option=None
This is a string. Specify the time when it will be sent. By default is None.
delivery_time_of_day=None
This is a string. Specify the time to live of the notification below deleting it for the user. By default is 3 days.
ttl=None
This is a string. Specify the priority. By default is normal. Use 10 to make it higher.
priority=None
## create_app
You can also create an app in OneSignal.com. Just run the following:
**NOTE**: You need to start the client with your auth_key. Without that you will not
be able to create apps.
from pbsonesignal import PybossaOneSignal
client = PybossaOneSignal(api_key="yourkey", app_id="ID", auth_key="yourkey")
client.create_app('name_app', 'https://yourdoamin.com', 'https://yourdomain/icon.png')
You can use the following arguments for this method.
This is a string. The name of the app you will be creating in OneSignal.
name='yourappname'
This is a string. The URL of the site that you will be linking to the app.
chrome_web_origin='https://yoursite.com'
WARNING: Read their docs, but you need full HTTPS in your site so this can work.
This is a string. The URL of the default notification icon
chrome_web_default_notification_icon='https://yoursite.com/assets/img/icon.png'
WARNING: Read their docs, but you need full HTTPS in your site so this can work.
If you build the wrong push message or you create the wrong app, you will get in the console and also an exception with information about it.
Copyright 2017 Scifabric LTD.
Source Code License: The GNU Affero General Public License, either version 3 of the License or (at your option) any later version. (see COPYING file)
The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software.
Documentation and media is under a Creative Commons Attribution License version 3.