LiveHelperChat / livehelperchat

Live Helper Chat - live support for your website. Featuring web and mobile apps, Voice & Video & ScreenShare. Supports Telegram, Twilio (whatsapp), Facebook messenger including building a bot.
http://livehelperchat.com
Apache License 2.0
1.93k stars 696 forks source link

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

Open Find-Detail opened 1 month ago

Find-Detail commented 1 month ago

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 commented 1 month ago
  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 commented 1 month ago

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;
    }

}

?>