<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class WhatsAppWebhookController extends Controller
{
    //Working
    public function verify(Request $request)
    {
        $verify_token = env('WHATSAPP_VERIFY_TOKEN');
        $mode = $request->get('hub_mode');
        $token = $request->get('hub_verify_token');
        $challenge = $request->get('hub_challenge');

        if ($mode === 'subscribe' && $token === $verify_token) {
            return response($challenge, 200);
        }

        return response('Invalid', 403);
    }

    public function receive(Request $request)
    {
        // Log or store the message
        \Log::info('Incoming Message: ', $request->all());

        return response('EVENT_RECEIVED', 200);
    }

}
