Add inital support for FCM push notifications

This commit is contained in:
Ramon Gutierrez 2023-06-13 20:33:58 +08:00
parent 82065bda93
commit 4990a3dc9d
15 changed files with 193 additions and 31 deletions

View file

@ -282,3 +282,9 @@ services:
App\Service\WarrantySerialLoadLogger:
arguments:
$em: "@doctrine.orm.entity_manager"
# FCM sender
App\Service\FCMSender:
arguments:
$server_key: "%env(FCM_SERVER_KEY)%"
$sender_id: "%env(FCM_SENDER_ID)%"

View file

@ -11,6 +11,7 @@ use Doctrine\ORM\EntityManagerInterface;
use App\Service\MQTTClient;
use App\Service\MQTTClientApiv2;
use App\Service\FCMSender;
use App\Entity\JobOrder;
use App\Entity\Rider;
@ -24,14 +25,16 @@ class UpdateUnacceptedJobOrdersCommand extends Command
// NOTE: for resq2 app
protected $mclientv2;
protected $fcmclient;
public function __construct(EntityManagerInterface $em, MQTTClient $mclient, MQTTClientApiv2 $mclientv2)
public function __construct(EntityManagerInterface $em, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient)
{
$this->em = $em;
$this->mclient = $mclient;
// NOTE: for resq2 app
$this->mclientv2 = $mclientv2;
$this->fcmclient = $fcmclient;
parent::__construct();
}
@ -50,6 +53,7 @@ class UpdateUnacceptedJobOrdersCommand extends Command
// NOTE: for resq2 app
$mclientv2 = $this->mclientv2;
$fcmclient = $this->fcmclient;
// TODO: get the timeout limit from .env
$timeout = 3;
@ -120,6 +124,7 @@ class UpdateUnacceptedJobOrdersCommand extends Command
// NOTE: for resq2 app
$mclientv2->sendEvent($jo, $payload);
$fcmclient->sendJoEvent($jo, "jo_fcm_title_outlet_assign", "jo_fcm_body_outlet_assign");
}
$rider = $jo->getRider();

View file

@ -28,6 +28,7 @@ use App\Service\RedisClientProvider;
use App\Service\RiderCache;
use App\Service\MQTTClient;
use App\Service\MQTTClientApiv2;
use App\Service\FCMSender;
use App\Service\WarrantyHandler;
use App\Service\JobOrderHandlerInterface;
use App\Service\InvoiceGeneratorInterface;
@ -438,7 +439,7 @@ class RiderAppController extends APIController
}
public function cancelJobOrder(Request $req, EntityManagerInterface $em, MQTTClient $mclient, MQTTClientApiv2 $mclientv2)
public function cancelJobOrder(Request $req, EntityManagerInterface $em, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient)
{
$required_params = ['jo_id'];
@ -486,6 +487,7 @@ class RiderAppController extends APIController
// NOTE: for resq2 app
$mclientv2->sendEvent($jo, $payload);
$fcmclient->sendJoEvent($jo, "jo_fcm_title_outlet_assign", "jo_fcm_body_outlet_assign");
$data = [];
return new APIResponse(true, 'Job order requeued.', $data);
@ -652,7 +654,7 @@ class RiderAppController extends APIController
}
public function arrive(Request $req, EntityManagerInterface $em, MQTTClient $mclient, MQTTClientApiv2 $mclientv2)
public function arrive(Request $req, EntityManagerInterface $em, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient)
{
$required_params = ['jo_id'];
@ -704,6 +706,7 @@ class RiderAppController extends APIController
// NOTE: for resq2 app
$mclientv2->sendEvent($jo, $payload);
$fcmclient->sendJoEvent($jo, "jo_fcm_title_driver_arrived", "jo_fcm_body_driver_arrived");
$data = [];
return new APIResponse(true, 'Rider arrived at customer location.', $data);
@ -756,7 +759,7 @@ class RiderAppController extends APIController
}
public function payment(Request $req, EntityManagerInterface $em, JobOrderHandlerInterface $jo_handler,
RisingTideGateway $rt, WarrantyHandler $wh, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, TranslatorInterface $translator)
RisingTideGateway $rt, WarrantyHandler $wh, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient, TranslatorInterface $translator)
{
$required_params = ['jo_id'];
@ -880,6 +883,7 @@ class RiderAppController extends APIController
// NOTE: for resq2 app
$mclientv2->sendEvent($jo, $payload);
$fcmclient->sendJoEvent($jo, "jo_fcm_title_fulfilled", "jo_fcm_body_fulfilled");
$data = [];
return new APIResponse(true, 'Job order paid and fulfilled.', $data);

View file

@ -9,6 +9,7 @@ use CrEOF\Spatial\PHP\Types\Geometry\Point;
use App\Service\InvoiceGeneratorInterface;
use App\Service\MQTTClient;
use App\Service\MQTTClientApiv2;
use App\Service\FCMSender;
use App\Service\RiderTracker;
use App\Service\GeofenceTracker;
use App\Service\MapTools;
@ -475,6 +476,7 @@ class JobOrderController extends ApiController
MapTools $map_tools,
InventoryManager $im,
MQTTClientApiv2 $mclientv2,
FCMSender $fcmclient,
RiderAssignmentHandlerInterface $rah,
PromoLogger $promo_logger,
HubSelector $hub_select,
@ -841,6 +843,7 @@ class JobOrderController extends ApiController
'event' => 'outlet_assign',
];
$mclientv2->sendEvent($jo, $payload);
$fcmclient->sendJoEvent($jo, "jo_fcm_title_outlet_assign", "jo_fcm_body_outlet_assign");
$rah->assignJobOrder($jo, $jo->getRider());
}
@ -859,6 +862,7 @@ class JobOrderController extends ApiController
'event' => 'outlet_assign',
];
$mclientv2->sendEvent($jo, $payload);
$fcmclient->sendJoEvent($jo, "jo_fcm_title_outlet_assign", "jo_fcm_body_outlet_assign");
}
$this->em->flush();
@ -933,6 +937,7 @@ class JobOrderController extends ApiController
MapTools $map_tools,
InventoryManager $im,
MQTTClientApiv2 $mclientv2,
FCMSender $fcmclient,
RiderAssignmentHandlerInterface $rah,
PromoLogger $promo_logger,
HubSelector $hub_select,
@ -1185,6 +1190,7 @@ class JobOrderController extends ApiController
'event' => 'outlet_assign',
];
$mclientv2->sendEvent($jo, $payload);
$fcmclient->sendJoEvent($jo, "jo_fcm_title_outlet_assign", "jo_fcm_body_outlet_assign");
$rah->assignJobOrder($jo, $jo->getRider());
}

View file

@ -22,6 +22,7 @@ use App\Service\GISManagerInterface;
use App\Service\MapTools;
use App\Service\MQTTClient;
use App\Service\MQTTClientApiv2;
use App\Service\FCMSender;
use App\Service\APNSClient;
use App\Service\InventoryManager;
use App\Service\HubSelector;
@ -354,7 +355,7 @@ class JobOrderController extends Controller
return $this->render($template, $params);
}
public function processingSubmit(Request $req, JobOrderHandlerInterface $jo_handler, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, $id)
public function processingSubmit(Request $req, JobOrderHandlerInterface $jo_handler, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient, $id)
{
$this->denyAccessUnlessGranted('jo_proc.list', null, 'No access.');
@ -362,7 +363,7 @@ class JobOrderController extends Controller
$error_array = [];
try
{
$error_array = $jo_handler->dispatchJobOrder($req, $id, $mclient, $mclientv2);
$error_array = $jo_handler->dispatchJobOrder($req, $id, $mclient, $mclientv2, $fcmclient);
}
catch (AccessDeniedHttpException $e)
{
@ -421,7 +422,7 @@ class JobOrderController extends Controller
}
public function assigningSubmit(Request $req, JobOrderHandlerInterface $jo_handler, MQTTCLient $mclient, APNSClient $aclient, $id)
public function assigningSubmit(Request $req, JobOrderHandlerInterface $jo_handler, MQTTCLient $mclient, FCMSender $fcmclient, APNSClient $aclient, $id)
{
$this->denyAccessUnlessGranted('jo_assign.list', null, 'No access.');
@ -481,7 +482,7 @@ class JobOrderController extends Controller
return $this->render($template, $params);
}
public function fulfillmentSubmit(Request $req, JobOrderHandlerInterface $jo_handler, MQTTClient $mclient, $id)
public function fulfillmentSubmit(Request $req, JobOrderHandlerInterface $jo_handler, MQTTClient $mclient, FCMSender $fcmclient, $id)
{
$this->denyAccessUnlessGranted('jo_fulfill.list', null, 'No access.');
@ -540,7 +541,7 @@ class JobOrderController extends Controller
return $this->render($template, $params);
}
public function openHubSubmit(Request $req, JobOrderHandlerInterface $jo_handler, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, $id)
public function openHubSubmit(Request $req, JobOrderHandlerInterface $jo_handler, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient, $id)
{
$this->denyAccessUnlessGranted('jo_open.list', null, 'No access.');
@ -549,7 +550,7 @@ class JobOrderController extends Controller
try
{
$error_array = $jo_handler->setHub($req, $id, $mclient, $mclientv2);
$error_array = $jo_handler->setHub($req, $id, $mclient, $mclientv2, $fcmclient);
}
catch (NotFoundHttpException $e)
{
@ -598,7 +599,7 @@ class JobOrderController extends Controller
return $this->render($template, $params);
}
public function openRiderSubmit(Request $req, JobOrderHandlerInterface $jo_handler, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, $id)
public function openRiderSubmit(Request $req, JobOrderHandlerInterface $jo_handler, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient, $id)
{
$this->denyAccessUnlessGranted('jo_open.list', null, 'No access.');
@ -607,7 +608,7 @@ class JobOrderController extends Controller
try
{
$error_array = $jo_handler->setRider($req, $id, $mclient, $mclientv2);
$error_array = $jo_handler->setRider($req, $id, $mclient, $mclientv2, $fcmclient);
}
catch (NotFoundHttpException $e)
{
@ -681,7 +682,7 @@ class JobOrderController extends Controller
]);
}
public function cancelJobOrder(Request $req, JobOrderHandlerInterface $jo_handler, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, $id)
public function cancelJobOrder(Request $req, JobOrderHandlerInterface $jo_handler, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient, $id)
{
$this->denyAccessUnlessGranted('joborder.cancel', null, 'No access.');
@ -698,7 +699,7 @@ class JobOrderController extends Controller
try
{
$jo_handler->cancelJobOrder($req, $id, $mclient, $mclientv2);
$jo_handler->cancelJobOrder($req, $id, $mclient, $mclientv2, $fcmclient);
}
catch (NotFoundHttpException $e)
{

View file

@ -34,6 +34,7 @@ use App\Service\InvoiceGeneratorInterface;
use App\Service\RisingTideGateway;
use App\Service\MQTTClient;
use App\Service\MQTTClientApiv2;
use App\Service\FCMSender;
use App\Service\GeofenceTracker;
use App\Service\InventoryManager;
use App\Service\RiderAssignmentHandlerInterface;
@ -74,6 +75,7 @@ class JobOrderController extends APIController
// TODO: break this monolithic method down
public function requestJobOrder(Request $req, InvoiceGeneratorInterface $ic, GeofenceTracker $geo,
InventoryManager $im, MQTTClient $mclient, MQTTClientApiv2 $mclientv2,
FCMSender $fcmclient,
RiderAssignmentHandlerInterface $rah, PromoLogger $promo_logger,
HubSelector $hub_select, HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger,
HubFilteringGeoChecker $hub_geofence, EntityManagerInterface $em)
@ -356,6 +358,7 @@ class JobOrderController extends APIController
// NOTE: for resq2 app
$mclientv2->sendEvent($jo, $payload);
$fcmclient->sendJoEvent($jo, "jo_fcm_title_outlet_assign", "jo_fcm_body_outlet_assign");
$rah->assignJobOrder($jo, $jo->getRider());
}
@ -378,6 +381,7 @@ class JobOrderController extends APIController
// NOTE: for resq2 app
$mclientv2->sendEvent($jo, $payload);
$fcmclient->sendJoEvent($jo, "jo_fcm_title_outlet_assign", "jo_fcm_body_outlet_assign");
}
$em->flush();

92
src/Service/FCMSender.php Normal file
View file

@ -0,0 +1,92 @@
<?php
namespace App\Service;
use Symfony\Contracts\Translation\TranslatorInterface;
use Fcm\FcmClient;
use Fcm\Push\Notification;
use App\Entity\JobOrder;
class FCMSender
{
protected $client;
protected $translator;
public function __construct(TranslatorInterface $translator, $server_key, $sender_id)
{
$this->client = new FcmClient($server_key, $sender_id);
$this->translator = $translator;
}
public function send($recipients, $title, $body, $data = [], $color = null, $sound = null, $badge = null)
{
$notification = new Notification();
$notification->setTitle($title)
->setBody($body);
foreach ($recipients as $recipient) {
$notification->addRecipient($recipient);
}
if (!empty($color)) {
$notification->setColor($color);
}
if (!empty($sound)) {
$notification->setSound($sound);
}
if (!empty($color)) {
$notification->setColor($color);
}
if (!empty($badge)) {
$notification->setBadge($badge);
}
if (!empty($data)) {
$notification->addDataArray($data);
}
return $this->client->send($notification);
}
public function sendJoEvent(JobOrder $job_order, $title, $body, $data = [])
{
// get all v2 sessions
$sessions = [];
$cust_user = $job_order->getCustomer()->getCustomerUser();
if (!empty($cust_user)) {
$sessions = $cust_user->getMobileSessions();
}
if (empty($sessions)) {
error_log("no sessions to send fcm notification to");
return;
}
$device_ids = [];
// send to every customer session
foreach ($sessions as $sess) {
$device_id = $sess->getDevicePushID();
error_log($sess->getID());
if (!empty($device_id)) {
// send fcm notification
$device_ids[] = $device_id;
}
}
if (empty($device_ids)) {
error_log("no devices to send fcm notification to");
return;
}
// send fcm notification
$result = $this->send($device_ids, $this->translator->trans($title), $this->translator->trans($body), $data);
return $result;
}
}

View file

@ -47,6 +47,7 @@ use App\Service\CustomerHandlerInterface;
use App\Service\WarrantyHandler;
use App\Service\MQTTClient;
use App\Service\MQTTClientApiv2;
use App\Service\FCMSender;
use App\Service\APNSClient;
use App\Service\MapTools;
@ -669,7 +670,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
}
// dispatch job order
public function dispatchJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2)
public function dispatchJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient)
{
// get object data
$em = $this->em;
@ -797,6 +798,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
// NOTE: for resq2 app
$mclientv2->sendEvent($obj, $payload);
$fcmclient->sendJoEvent($obj, "jo_fcm_title_outlet_assign", "jo_fcm_body_outlet_assign");
}
return $error_array;
@ -1031,7 +1033,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
}
// cancel job order
public function cancelJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2)
public function cancelJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient)
{
// get object data
$em = $this->em;
@ -1075,10 +1077,11 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
// NOTE: for resq2 app
$mclientv2->sendEvent($obj, $payload);
$fcmclient->sendJoEvent($obj, "jo_fcm_title_cancelled", "jo_fcm_body_cancelled", ['reason' => $cancel_reason]);
}
// set hub for job order
public function setHub($req, $id, $mclient, $mclientv2)
public function setHub($req, $id, $mclient, $mclientv2, $fcmclient)
{
// get object data
$em = $this->em;
@ -1181,6 +1184,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
// NOTE: for resq2 app
$mclientv2->sendEvent($obj, $payload);
$fcmclient->sendJoEvent($obj, "jo_fcm_title_outlet_assign", "jo_fcm_body_outlet_assign");
}
return $error_array;
@ -1282,7 +1286,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
}
// set rider for job order
public function setRider($req, $id, $mclient, $mclientv2)
public function setRider($req, $id, $mclient, $mclientv2, $fcmclient)
{
// initialize error list
$error_array = [];
@ -1385,6 +1389,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
// NOTE: for resq2 app
$mclientv2->sendEvent($obj, $payload);
$fcmclient->sendJoEvent($obj, "jo_fcm_title_driver_assigned", "jo_fcm_body_driver_assigned");
}
return $error_array;

View file

@ -58,6 +58,7 @@ use App\Service\RiderAssignmentHandlerInterface;
use App\Service\WarrantyHandler;
use App\Service\MQTTClient;
use App\Service\MQTTClientApiv2;
use App\Service\FCMSender;
use App\Service\APNSClient;
use App\Service\MapTools;
use App\Service\RisingTideGateway;
@ -804,7 +805,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
}
// dispatch job order
public function dispatchJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2)
public function dispatchJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient)
{
// get object data
$em = $this->em;
@ -985,7 +986,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
// NOTE: for resq2 app
$mclientv2->sendEvent($obj, $payload);
$fcmclient->sendJoEvent($obj, "jo_fcm_title_outlet_assign", "jo_fcm_body_outlet_assign");
// update redis hub jo count
$this->hub_dist->incrementJoCountForHub($hub);
@ -1342,7 +1343,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
}
// cancel job order
public function cancelJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2)
public function cancelJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient)
{
// get object data
$em = $this->em;
@ -1390,10 +1391,11 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
// NOTE: for resq2 app
$mclientv2->sendEvent($obj, $payload);
$fcmclient->sendJoEvent($obj, "jo_fcm_title_cancelled", "jo_fcm_body_cancelled", ['reason' => $cancel_reason]);
}
// set hub for job order
public function setHub($req, $id, $mclient, $mclientv2)
public function setHub($req, $id, $mclient, $mclientv2, $fcmclient)
{
// get object data
$em = $this->em;
@ -1570,6 +1572,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
// NOTE: for resq2 app
$mclientv2->sendEvent($obj, $payload);
$fcmclient->sendJoEvent($obj, "jo_fcm_title_outlet_assign", "jo_fcm_body_outlet_assign");
// update redis hub_jo_count for hub
// decrement old hub's count and increment new hub's count
@ -1678,7 +1681,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
}
// set rider for job order
public function setRider($req, $id, $mclient, $mclientv2)
public function setRider($req, $id, $mclient, $mclientv2, $fcmclient)
{
// initialize error list
$error_array = [];
@ -1854,6 +1857,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
// NOTE: for resq2 app
$mclientv2->sendEvent($obj, $payload);
$fcmclient->sendJoEvent($obj, "jo_fcm_title_driver_assigned", "jo_fcm_body_driver_assigned");
}
return $error_array;

View file

@ -6,6 +6,7 @@ use Symfony\Component\HttpFoundation\Request;
use App\Service\MQTTClient;
use App\Service\MQTTClientApiv2;
use App\Service\FCMSender;
use App\Service\APNSClient;
use App\Service\MapTools;
use App\Service\HubSelector;
@ -30,7 +31,7 @@ interface JobOrderHandlerInterface
public function processOneStepJobOrder(Request $req, int $id);
// dispatch job order
public function dispatchJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2);
public function dispatchJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient);
// assign job order
public function assignJobOrder(Request $req, int $id);
@ -39,16 +40,16 @@ interface JobOrderHandlerInterface
public function fulfillJobOrder(Request $req, int $id);
// cancel job order
public function cancelJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2);
public function cancelJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient);
// set hub for job order
public function setHub(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2);
public function setHub(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient);
// reject hub for job order
public function rejectHub(Request $req, int $id);
// set rider for job order
public function setRider(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2);
public function setRider(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient);
// unlock processor
public function unlockProcessor(int $id);

View file

@ -19,6 +19,7 @@ use App\Service\RedisClientProvider;
use App\Service\RiderCache;
use App\Service\MQTTClient;
use App\Service\MQTTClientApiv2;
use App\Service\FCMSender;
use App\Service\WarrantyHandler;
use App\Service\JobOrderHandlerInterface;
use App\Service\InvoiceGeneratorInterface;
@ -44,6 +45,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
protected $country_code;
protected $mclient;
protected $mclientv2;
protected $fcmclient;
protected $wh;
protected $jo_handler;
protected $ic;
@ -51,7 +53,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
public function __construct(EntityManagerInterface $em, RedisClientProvider $redis,
EncoderFactoryInterface $ef, RiderCache $rcache,
string $country_code, MQTTClient $mclient, MQTTClientApiv2 $mclientv2,
string $country_code, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient,
WarrantyHandler $wh, JobOrderHandlerInterface $jo_handler,
InvoiceGeneratorInterface $ic)
{
@ -62,6 +64,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
$this->country_code = $country_code;
$this->mclient = $mclient;
$this->mclientv2 = $mclientv2;
$this->fcmclient = $fcmclient;
$this->wh = $wh;
$this->jo_handler = $jo_handler;
$this->ic = $ic;
@ -429,6 +432,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
// NOTE: for resq2 app
$this->mclientv2->sendEvent($jo, $payload);
$this->fcmclient->sendJoEvent($jo, "jo_fcm_title_outlet_assign", "jo_fcm_body_outlet_assign");
return $data;
}
@ -473,6 +477,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
// NOTE: for resq2 app
$this->mclientv2->sendEvent($jo, $payload);
$this->fcmclient->sendJoEvent($jo, "jo_fcm_title_driver_arrived", "jo_fcm_body_driver_arrived");
return $data;
}
@ -589,6 +594,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
// NOTE: for resq2 app
$this->mclientv2->sendEvent($jo, $payload);
$this->fcmclient->sendJoEvent($jo, "jo_fcm_title_fulfilled", "jo_fcm_body_fulfilled");
return $data;
}

View file

@ -22,6 +22,7 @@ use App\Service\RedisClientProvider;
use App\Service\RiderCache;
use App\Service\MQTTClient;
use App\Service\MQTTClientApiv2;
use App\Service\FCMSender;
use App\Service\WarrantyHandler;
use App\Service\JobOrderHandlerInterface;
use App\Service\InvoiceGeneratorInterface;
@ -49,6 +50,7 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface
protected $country_code;
protected $mclient;
protected $mclientv2;
protected $fcmclient;
protected $wh;
protected $jo_handler;
protected $ic;
@ -58,7 +60,7 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface
public function __construct(EntityManagerInterface $em, RedisClientProvider $redis,
EncoderFactoryInterface $ef, RiderCache $rcache,
string $country_code, MQTTClient $mclient, MQTTClientApiv2 $mclientv2,
string $country_code, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient,
WarrantyHandler $wh, JobOrderHandlerInterface $jo_handler,
InvoiceGeneratorInterface $ic, RisingTideGateway $rt,
RiderTracker $rider_tracker, TranslatorInterface $translator)
@ -70,6 +72,7 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface
$this->country_code = $country_code;
$this->mclient = $mclient;
$this->mclientv2 = $mclientv2;
$this->fcmclient = $fcmclient;
$this->wh = $wh;
$this->jo_handler = $jo_handler;
$this->ic = $ic;
@ -471,6 +474,7 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface
// NOTE: for resq2 app
$this->mclientv2->sendEvent($jo, $payload);
$this->fcmclient->sendJoEvent($jo, "jo_fcm_title_outlet_assign", "jo_fcm_body_outlet_assign");
return $data;
}
@ -515,6 +519,7 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface
// NOTE: for resq2 app
$this->mclientv2->sendEvent($jo, $payload);
$this->fcmclient->sendJoEvent($jo, "jo_fcm_title_driver_arrived", "jo_fcm_body_driver_arrived");
return $data;
}
@ -672,6 +677,7 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface
// NOTE: for resq2 app
$this->mclientv2->sendEvent($jo, $payload);
$fcmclient->sendJoEvent($jo, "jo_fcm_title_fulfilled", "jo_fcm_body_fulfilled");
return $data;
}

View file

@ -7,6 +7,7 @@ use Doctrine\ORM\EntityManagerInterface;
use App\Service\RiderAssignmentHandlerInterface;
use App\Service\MQTTClient;
use App\Service\MQTTClientApiv2;
use App\Service\FCMSender;
use App\Service\APNSClient;
use App\Entity\JobOrder;
@ -20,12 +21,14 @@ class CMBRiderAssignmentHandler implements RiderAssignmentHandlerInterface
protected $aclient;
protected $mclient;
protected $mclientv2;
protected $fcmclient;
public function __construct(EntityManagerInterface $em, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, APNSClient $aclient)
public function __construct(EntityManagerInterface $em, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient, APNSClient $aclient)
{
$this->em = $em;
$this->mclient = $mclient;
$this->mclientv2 = $mclientv2;
$this->fcmclient = $fcmclient;
$this->aclient = $aclient;
}
@ -42,6 +45,7 @@ class CMBRiderAssignmentHandler implements RiderAssignmentHandlerInterface
// NOTE: for resq2 app
$this->mclientv2->sendEvent($obj, $payload);
$this->fcmclient->sendJoEvent($obj, "jo_fcm_title_driver_assigned", "jo_fcm_body_driver_assigned");
// check if rider is available
if ($rider->isAvailable())
@ -73,6 +77,7 @@ class CMBRiderAssignmentHandler implements RiderAssignmentHandlerInterface
// NOTE: for resq2 app
$this->mclientv2->sendEvent($obj, $payload);
$this->fcmclient->sendJoEvent($obj, "jo_fcm_title_fulfilled", "jo_fcm_body_fulfilled");
// send fulfill/complete event to rider
$this->mclient->sendRiderEvent($obj, $payload);

View file

@ -9,6 +9,7 @@ use Symfony\Contracts\Translation\TranslatorInterface;
use App\Service\RiderAssignmentHandlerInterface;
use App\Service\MQTTClient;
use App\Service\MQTTClientApiv2;
use App\Service\FCMSender;
use App\Service\APNSClient;
use App\Entity\JobOrder;
@ -22,13 +23,15 @@ class ResqRiderAssignmentHandler implements RiderAssignmentHandlerInterface
protected $aclient;
protected $mclient;
protected $mclientv2;
protected $fcmclient;
protected $translator;
public function __construct(EntityManagerInterface $em, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, APNSClient $aclient, TranslatorInterface $translator)
public function __construct(EntityManagerInterface $em, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient, APNSClient $aclient, TranslatorInterface $translator)
{
$this->em = $em;
$this->mclient = $mclient;
$this->mclientv2 = $mclientv2;
$this->fcmclient = $fcmclient;
$this->aclient = $aclient;
$this->translator = $translator;
}
@ -46,6 +49,7 @@ class ResqRiderAssignmentHandler implements RiderAssignmentHandlerInterface
// NOTE: for resq2 app
$this->mclientv2->sendEvent($obj, $payload);
$this->fcmclient->sendJoEvent($obj, "jo_fcm_title_driver_assigned", "jo_fcm_body_driver_assigned");
// check if rider is available
if ($rider->isAvailable())
@ -79,6 +83,7 @@ class ResqRiderAssignmentHandler implements RiderAssignmentHandlerInterface
// NOTE: for resq2 app
$this->mclientv2->sendEvent($obj, $payload);
$this->fcmclient->sendJoEvent($obj, "jo_fcm_title_fulfilled", "jo_fcm_body_fulfilled");
// send fulfill/complete event to rider
$this->mclient->sendRiderEvent($obj, $payload);

View file

@ -25,3 +25,15 @@ image_jo_pdf: /public/assets/images/logo-resq.png
default_lat: 14.6091
default_long: 121.0223
default_region: ph
# fcm jo status updates
jo_fcm_title_outlet_assign: Looking for riders
jo_fcm_title_driver_assigned: Rider found
jo_fcm_title_driver_arrived: Rider nearby
jo_fcm_title_cancelled: Order cancelled
jo_fcm_title_fulfilled: Thank you!
jo_fcm_body_outlet_assign: We're assigning a rider for your order, please wait.
jo_fcm_body_driver_assigned: A rider is on their way.
jo_fcm_body_driver_arrived: Your order is almost there!
jo_fcm_body_cancelled: Your order has been cancelled.
jo_fcm_body_fulfilled: Order complete! Your receipt is ready.