<commit_before><?php
/**
 * User: casperlai
 * Date: 2016/8/31
 * Time: 上午12:35
 */

namespace Casperlaitw\LaravelFbMessenger\Controllers;

use Casperlaitw\LaravelFbMessenger\Contracts\BaseHandler;
use Casperlaitw\LaravelFbMessenger\Contracts\WebhookHandler;
use Casperlaitw\LaravelFbMessenger\Exceptions\NeedImplementHandlerException;
use Casperlaitw\LaravelFbMessenger\Messages\Receiver;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

/**
 * Class WebhookController
 * @package Casperlaitw\LaravelFbMessenger\Controllers
 */
class WebhookController extends Controller
{
    /**
     * @var Repository
     */
    private $config;

    /**
     * WebhookController constructor.
     *
     * @param Repository $config
     */
    public function __construct(Repository $config)
    {
        $this->config = $config;
    }

    /**
     * @param Request $request
     *
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response|void
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
     * @throws \InvalidArgumentException
     */
    public function index(Request $request)
    {
        if ($request->get('hub_mode') === 'subscribe'
            && $request->get('hub_verify_token') === $this->config->get('fb-messenger.verify_token')) {
            return new Response($request->get('hub_challenge'));
        }

        throw new NotFoundHttpException('Not found resources');
    }

    /**
     * @param Request $request
     *
     * @throws NeedImplementHandlerException
     */
    public function receive(Request $request)
    {
        $receive = new Receiver($request);
        $handleClassName = config('fb-messenger.handler');
        $handle = (new $handleClassName)
            ->setMessages($receive->getMessages());
        if (!$handle instanceof BaseHandler) {
            throw new NeedImplementHandlerException();
        }
        $webhook = new WebhookHandler($handle, $token);
        $webhook->handle();
    }
}<commit_msg>fix: Fix miss app token<commit_after><?php
/**
 * User: casperlai
 * Date: 2016/8/31
 * Time: 上午12:35
 */

namespace Casperlaitw\LaravelFbMessenger\Controllers;

use Casperlaitw\LaravelFbMessenger\Contracts\BaseHandler;
use Casperlaitw\LaravelFbMessenger\Contracts\WebhookHandler;
use Casperlaitw\LaravelFbMessenger\Exceptions\NeedImplementHandlerException;
use Casperlaitw\LaravelFbMessenger\Messages\Receiver;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

/**
 * Class WebhookController
 * @package Casperlaitw\LaravelFbMessenger\Controllers
 */
class WebhookController extends Controller
{
    /**
     * @var Repository
     */
    private $config;

    /**
     * WebhookController constructor.
     *
     * @param Repository $config
     */
    public function __construct(Repository $config)
    {
        $this->config = $config;
    }

    /**
     * @param Request $request
     *
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response|void
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
     * @throws \InvalidArgumentException
     */
    public function index(Request $request)
    {
        if ($request->get('hub_mode') === 'subscribe'
            && $request->get('hub_verify_token') === $this->config->get('fb-messenger.verify_token')) {
            return new Response($request->get('hub_challenge'));
        }

        throw new NotFoundHttpException('Not found resources');
    }

    /**
     * @param Request $request
     *
     * @throws NeedImplementHandlerException
     */
    public function receive(Request $request)
    {
        $receive = new Receiver($request);
        $handleClassName = $this->config->get('fb-messenger.handler');
        $token = $this->config->get('fb-messenger.app_token');
        $handle = (new $handleClassName)
            ->setMessages($receive->getMessages());
        if (!$handle instanceof BaseHandler) {
            throw new NeedImplementHandlerException();
        }
        $webhook = new WebhookHandler($handle, $token);
        $webhook->handle();
    }
}
{'fraction_non_alphanumeric': 0.12058492688413948, 'fraction_numerical': 0.0049493813273340835, 'mean_word_length': 3.2586206896551726, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4610405', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1276, 'n_words': 218}