public static function findByTypeAndPattern($type = '', $pattern = '')
    {
        $where       = '1 = 1';
        $where_type  = '';
        $where_like  = '';
        $where_rlike = '';

        $placeholder = [];

        // Check type, pattern is email or phone number when passing from quick replies
        if ($type === 'payload') {
            $pattern = filter_var($pattern, FILTER_VALIDATE_EMAIL) ? 'user_email' : $pattern;
            $pattern = is_phone_number($pattern) ? 'user_phone_number' : $pattern;
        }

        if (!empty($type)) {
            $where_type           = ' AND type = :type';
            $placeholder[':type'] = $type;
        }

        if (!empty($pattern)) {
            $placeholder[':pattern'] = $pattern;
            $where_like              = ' AND :pattern LIKE pattern';
            $where_rlike             = " AND :pattern RLIKE CONCAT('^',pattern,'$')";
        }

        $columns = ['type', 'pattern', 'answers', 'wait', 'sources', 'messaging_type', 'notification_type'];

        // Where Like First
        $nodes = self::whereRaw($where . $where_type . $where_like, $placeholder)->get($columns);
        
        // If Not Found. Then Where Rlike
        if ($nodes->count() === 0) {
            $nodes = self::whereRaw($where . $where_type . $where_rlike, $placeholder)->get($columns);
        }

        // If still not found, then try NLP and find
        if ($nodes->count() === 0 && Conversation::has('nlp')) {
            $entities = Conversation::get('nlp')->getNames();

            if (! empty($entities)) {
                $entities = '#' . ltrim(implode('|#', $entities), '|');
                
                $nodes = self::whereRaw('pattern RLIKE :pattern', [
                    ':pattern' => $entities,
                ])->get($columns);

                // Enable nodes filter. Available types: first, last, any. Default: first
                $nodes = $nodes->filter(function ($node) {
                    return Conversation::get('nlp')->filter($node->pattern)->exists();
                });
            }
        }

        return $nodes;
    }