norkunas / onesignal-php-api

OneSignal API for PHP
MIT License
234 stars 83 forks source link

Send One Signal push notification with Symfony 3 #85

Closed valentin-harrang closed 6 years ago

valentin-harrang commented 6 years ago

I created a mobile application with Ionic 3 and I would like send notification in Symfony 3 via One Signal.

I read the documentation of One Signal and this documentation: https://github.com/norkunas/onesignal-php-api/blob/master/docs/setup-guzzle5.md

I created a service in Symfony, but I'm blocked, I do not know what to put in.

$guzzle = new GuzzleClient([ // ..config ]);

My service :

`namespace SGBundle\Service\OneSignal;

use GuzzleHttp\Client as GuzzleClient; use Http\Adapter\Guzzle5\Client as GuzzleAdapter; use Http\Client\Common\HttpMethodsClient as HttpClient; use Http\Message\MessageFactory\GuzzleMessageFactory; use OneSignal\Config; use OneSignal\Devices; use OneSignal\OneSignal; use SGBundle\Controller\BaseController;

class OneSignalService extends BaseController {

public function sendMessage()
{
    $config = new Config();
    $config->setApplicationId('xxx');
    $config->setApplicationAuthKey('xx');
    $config->setUserAuthKey('xxx');

    $guzzle = new GuzzleClient([
                                   // ..config
                               ]);

    $client = new HttpClient(new GuzzleAdapter($guzzle), new GuzzleMessageFactory());
    $api = new OneSignal($config, $client);

}`

And where I define the body of my notification (title and message for example) ?

Thank you in advance for your help

norkunas commented 6 years ago

Most of the time default guzzle configuration is enough for api usage, but if you think you need to configure something then I suggest to you to read it's documentation http://docs.guzzlephp.org/.

As for sending notifications you can find some examples here: https://github.com/norkunas/onesignal-php-api/blob/master/docs/getting-started.md#notifications