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

visitor on mobile app and Cloud Messaging API (Legacy) issue #2106

Open
Find-Detail opened this issue May 26, 2024 · 2 comments
Open

visitor on mobile app and Cloud Messaging API (Legacy) issue #2106

Find-Detail opened this issue May 26, 2024 · 2 comments

Comments

@Find-Detail
Copy link

mobile app is working after last update but visitor are not showing in mobile app

second Cloud Messaging API (Legacy) deprecated on 6/20/2023 so migrate to the latest Firebase Cloud Messaging API (HTTP v1) by 6/20/2024 because of this if you create new app in firebase FCM key not found kindly add Firebase Cloud Messaging API (HTTP v1)

@remdex
Copy link
Contributor

remdex commented May 27, 2024

  1. Visitors never showed up in the mobile app only chats.
  2. Kindly create a pull request with FCM part improvements :)
  3. And for best mobile app support it's recommended now just use https://github.com/LiveHelperChat/telegram you can use this app as your mobile app to support your chats.

@Find-Detail
Copy link
Author

Find-Detail commented May 27, 2024

anyone can please test

 function getAccessToken() {
       $keyFilePath = __DIR__ . '/service-account.json'; // Path to your service account JSON file
       $keyFileContents = file_get_contents($keyFilePath);
       $key = json_decode($keyFileContents, true);
   
       $client = new Google_Client();
       $client->setAuthConfig($key);
       $client->setScopes(SCOPES);
   
       // Fetch access token
       $accessToken = $client->fetchAccessTokenWithAssertion();
       return $accessToken['access_token'];
   }
   
   // Update your sendAndoid function to use the access token
   public static function sendAndoid(erLhcoreClassModelUserSession $session, $chat, $params = array())
   {
       $options = erLhcoreClassModelChatConfig::fetch('mobile_options')->data;
   
       if (!isset($options['fcm_project_id']) || !isset($options['fcm_server_key'])) {
           throw new Exception('FCM Project ID or Server Key is not set');
       }
   
       $url = 'https://fcm.googleapis.com/v1/projects/' . $options['fcm_project_id'] . '/messages:send';
   
       $message = isset($params['msg']) ? preg_replace('#\[[^\]]+\]#', '',strip_tags($params['msg'])) : preg_replace('#\[[^\]]+\]#', '', erLhcoreClassChat::getGetLastChatMessagePending($chat->id));
   
       $data = [
           'message' => [
               'token' => $session->device_token,
               'notification' => [
                   'title' => $params['title'],
                   'body' => $message
               ],
               'data' => [
                   'click_action' => 'FLUTTER_NOTIFICATION_CLICK',
                   'server_id' => $session->token,
                   'm' => $params['title'],
                   'chat_type' => $params['chat_type'],
                   'msg' => $message,
                   'chat' => json_encode($chat->getState())
               ]
           ]
       ];
   
       $headers = [
           'Authorization: Bearer ' . getAccessToken(), // Get access token
           'Content-Type: application/json'
       ];
   
       $ch = curl_init();
       curl_setopt($ch, CURLOPT_URL, $url);
       curl_setopt($ch, CURLOPT_POST, true);
       curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
       curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
       curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
       $result = curl_exec($ch);
       curl_close($ch);
   
       $responseData = json_decode($result, true);
   
       if (isset($responseData['error'])) {
           throw new Exception('FCM Error: ' . $responseData['error']['message']);
       }
   
       return $responseData;
   }
   

}

?>

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

No branches or pull requests

2 participants