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

Issues sending to segments #151

Open
wout101media opened this issue Mar 29, 2023 · 0 comments
Open

Issues sending to segments #151

wout101media opened this issue Mar 29, 2023 · 0 comments

Comments

@wout101media
Copy link

Hi,

Maybe i'm just making a mistake and overlooking something but at the moment I'm trying to send notifications to all my OneSignal subscribers. I don't have their OneSIgnal player id's stored in my database because I'm creating a news application where people can subscribe but don't need an user account for it.
So the default laravel functionality in my controller
Notification::send(User::all(), new OneSignalNotification($news->title,'fijeoapwq', \route('admin.news.show',$news->id)));

Will not work for me. But testing with this and in User class hard coding
public function routeNotificationForOneSignal(){ return 'ONESIGNAL_PLAYER_ID'; }
Actually works for me but for the love of god i can't figure how to get it working sending the notification to my Active Users segment.
I have tried things like this in my OneSignalNotification class:

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use NotificationChannels\OneSignal\OneSignalChannel;
use NotificationChannels\OneSignal\OneSignalMessage;
class OneSignalNotification extends Notification
{
    use Queueable;


    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct(public string $subject, public string $body, public string $url)
    {
        //
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
            return [OneSignalChannel::class];
    }

    public function toOneSignal($notifiable)
    {
        return OneSignalMessage::create()
                ->setSubject($this->subject)
                ->setBody($this->body)
                ->setUrl($this->url)
            ->setParameter('included_segments','Active Users');
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}

Is something broken or could someone help my figuring this out?

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

No branches or pull requests

1 participant