Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code One Signal library - no installation of tracardi needed. #847

Open
atompie opened this issue Nov 28, 2023 · 4 comments
Open

Code One Signal library - no installation of tracardi needed. #847

atompie opened this issue Nov 28, 2023 · 4 comments
Assignees
Labels
hacktoberfest Issues good for hacktoberfest

Comments

@atompie
Copy link
Collaborator

atompie commented Nov 28, 2023

Is your feature request related to a problem? Please describe.
Add library for one signal (https://onesignal.com)Place it in tracardi/service/onsignal

TASK IS DONE when:
[ ] Code is clear and simple to use (parameters have all required data to connect, eg. API KEY)
[ ] Test file is coded to see if the library works

This will help you get started (AI generated help - please verify if it works, and clean up the code):

Creating a package to send data to OneSignal, a service used for sending push notifications, involves a few key steps: obtaining API keys, setting up your development environment, writing the integration code, and testing to ensure it works properly. Below, I’ll guide you through each step:

1. Obtain OneSignal API Keys

To start interacting with OneSignal, you need to have API keys that authenticate your requests. Here’s how you can obtain them:

  1. Create a OneSignal account: If you haven’t already, you need to sign up for OneSignal at onesignal.com.
  2. Create an app: Once logged in, you can create a new application within OneSignal. This is typically done in your dashboard.
  3. Get API Key: After creating your app, you can find your REST API key and App ID in the app settings under Keys & IDs. These are essential for sending notifications.

2. Setup Development Environment

Choose your preferred programming environment and make sure you have the necessary tools and libraries installed. For example, if you're using Python, you might use libraries like requests to handle HTTP requests.

3. Write the Code

Here’s a simple Python example using the requests library to send a notification:

import requests
import json

def send_notification(app_id, api_key, contents, included_segments=["All"]):
    headers = {
        "Content-Type": "application/json; charset=utf-8",
        "Authorization": f"Basic {api_key}"
    }

    payload = {
        "app_id": app_id,
        "contents": {"en": contents},
        "included_segments": included_segments
    }

    response = requests.post("https://onesignal.com/api/v1/notifications",
                             headers=headers,
                             data=json.dumps(payload))

    return response.json()

# Replace 'your_app_id' and 'your_api_key' with your actual OneSignal App ID and REST API key.
app_id = "your_app_id"
api_key = "your_api_key"
message = "Hello, this is a test notification!"

result = send_notification(app_id, api_key, message)
print(result)

4. Test the Integration

After writing your code:

  • Local Testing: Test your function locally by calling it and checking if the notification is delivered to your device or segment as expected.
  • Debug: If it doesn’t work, check the response from OneSignal for any error messages. This can help in debugging issues related to API keys or payload structure.
  • Logging: Implement logging in your code to capture the request and response data for easier troubleshooting.

5. Deploy and Monitor

Once everything works locally:

  • Deploy: Move your code to a production or staging environment.
  • Monitor: Keep an eye on the interactions with OneSignal using logs and make sure to handle any potential errors or exceptions.

This should help you get started with integrating OneSignal into your application. Always ensure to secure your API keys and not expose them in your codebase publicly.

@atompie atompie added the hacktoberfest Issues good for hacktoberfest label Sep 14, 2024
@atompie atompie changed the title One Signal Plugin Code One Signal library - no installation of tracardi needed. Sep 14, 2024
@HazemAbdo
Copy link

@atompie I'd like to work on this feature.

@atompie
Copy link
Collaborator Author

atompie commented Sep 27, 2024

@HazemAbdo sure I assigned you to the task.

@HazemAbdo
Copy link

I will start working on it today

@atompie
Copy link
Collaborator Author

atompie commented Oct 18, 2024

Sure. Looking forward to it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest Issues good for hacktoberfest
Projects
None yet
Development

No branches or pull requests

2 participants