如何通知移动应用程序 Twilio 来电?已经使用节点服务器测试 Twilio 演示 android 应用程序,但它不工作

How to notify mobile app for Twilio inbound call? Already test Twilio demo android app with node server but it not working

public function mobileCallTwimlResponse(Request $request): VoiceResponse
    {
        $from = $request->From ?? config('services.twilio.number');
        $to = $request->To;
        $dial = $this->twimlResponse->dial(null, ['callerId' => $from]);

        if (!$to) {
            $this->twimlResponse->say('  "Congratulations! You have made your first call! Good bye."');
        } elseif (is_string($to)) {
            $dial->number($to);
        } else {
            $dial->client($from);
        }

        return $this->twimlResponse;
    }

    public function receiveCall(Request $request)
    {

        $account_sid = config('services.twilio.accountSid');
        $auth_token = config('services.twilio.authToken');
        $twilio_client = new Client($account_sid, $auth_token);
        $from = $request->From ?? config('services.twilio.number');
        $to = $request->To;
        $call = null;
        $url = route('mobile_receive_call');
        if (!$to) {
            $call = $twilio_client->calls->create("client:customer", $from,
                array(
                    "url" => $url,
                ));
        } elseif (is_numeric($to)) {
            $call = $twilio_client->calls->create($to, $from,
                array(
                    "url" => $url,
                ));
        } else {
            $to = "client:" . $to;
            $call = $twilio_client->calls->create($to, $from,
                array(
                    "url" => $url,
                ));
        }

        return $call->sid;
    }

    public function incomingCall()
    {
        return $this->twimlResponse->say('incoming call responding');
    }

我有上面的代码来接收到我的移动应用程序的来电,但我无法弄清楚 twilio 如何将来电通知发送到我的移动应用程序以及移动应用程序用户通过哪个来响应呼叫。我在令牌创建中设置了推送凭据 API

 private $accessToken;

    public function __construct(AccessToken $accessToken)
    {
        $this->accessToken = $accessToken;
    }

    public function token($applicationSid, $identity = 'customer', $page_url = null): string
    {
        $forPage = $page_url;
        /*if ($forPage === route('dashboard', [], false)) {
            $this->accessToken->setIdentity('support_agent');
        } else {
            $this->accessToken->setIdentity('customer');
        }*/

        $this->accessToken->setIdentity($identity);

        // Create Voice grant
        $voiceGrant = new VoiceGrant();
        $voiceGrant->setOutgoingApplicationSid($applicationSid);

        // Optional: add to allow incoming calls
        $voiceGrant->setIncomingAllow(true);
        $voiceGrant->setPushCredentialSid(config('services.twilio.push_credential_sid'));
        // Add grant to token
        $this->accessToken->addGrant($voiceGrant);

        // render token to string
        return $this->accessToken->toJWT();
    } 

但是 Twilio 如何通过 FCM 触发通知?它会自行处理,或者他们是否需要在服务器端编写代码以调用来电 Web 挂钩并通过该代码将来电通知发送到移动应用程序?

android/Ios 应用的令牌:

public function __construct(VoiceCallTokenService $callTokenService)
    {
        $this->callTokenService = $callTokenService;
    }

 public function tokenForMobile(): JsonResponse
    {
        $user = auth()->user();
        $identity = TwilioHelper::substrPhoneNumber($user->twilio_number);
        $this->callTokenService->setPushCredentialSid(config('services.twilio.ios_push_credential_sid'));
        $token = $this->callTokenService->token(config('services.twilio.applicationSidForMobile'), $identity);
        return response()->json(['voice_call_token' => $token]);
    }

辅助 SubStrPhoneNumber 方法:

public static function substrPhoneNumber($phone)
    {
        if ($phone[0] === "+") {
            $phone = substr($phone, 1);
        }
        return $phone;
    }

In 正在使用 $to 作为调用的身份:

$to = $request->To; //+923222333322

但是这个数字包含 + 号,通过排除 + 号它开始为我工作。即

$to = "923222333322"