Plugin Directory

Changeset 3426979


Ignore:
Timestamp:
12/24/2025 05:22:19 PM (3 months ago)
Author:
cnvrse
Message:

Corrected bug that prevented telegram validation QR code

Location:
cnvrse
Files:
120 added
4 edited

Legend:

Unmodified
Added
Removed
  • cnvrse/trunk/assets/js/cnvrse-admin-telegram.js

    r3426494 r3426979  
    1313    'DOMContentLoaded',
    1414    function () {
     15        console.log('[CNVRSE DEBUG] Telegram admin JS loaded');
     16        console.log('[CNVRSE DEBUG] cnvrseSettings:', cnvrseSettings);
     17        console.log('[CNVRSE DEBUG] cnvrseAdminParams:', cnvrseAdminParams);
     18
    1519        var tokenInput    = document.getElementById( 'cnvrse_telegram_bot_token' );
    1620        var chatIdInput   = document.getElementById( 'cnvrse_telegram_chat_id' );
     
    1923        var helper        = document.getElementById( 'cnvrse-connection-helper' );
    2024
     25        console.log('[CNVRSE DEBUG] Elements found:', {
     26            tokenInput: !!tokenInput,
     27            chatIdInput: !!chatIdInput,
     28            connectBtn: !!connectBtn,
     29            disconnectBtn: !!disconnectBtn,
     30            helper: !!helper
     31        });
     32
    2133        // isConnected logic derived from passed params
    2234        var isConnected = cnvrseAdminParams.isConnected;
     35        console.log('[CNVRSE DEBUG] isConnected:', isConnected);
    2336
    2437        var botUsername    = '';
     
    2841        // Connect button click
    2942        if (connectBtn && ! isConnected) {
     43            console.log('[CNVRSE DEBUG] Adding click listener to connect button');
    3044            connectBtn.addEventListener(
    3145                'click',
    3246                function () {
    3347                    var token = tokenInput.value.trim();
     48                    console.log('[CNVRSE DEBUG] Connect clicked, token length:', token.length);
     49                    console.log('[CNVRSE DEBUG] Token (first 10 chars):', token.substring(0, 10) + '...');
     50
    3451                    if ( ! token) {
    3552                        alert( cnvrseAdminParams.i18n.enterToken );
     
    4562                    helper.textContent = cnvrseAdminParams.i18n.validating;
    4663
     64                    var apiUrl = cnvrseSettings.apiUrl + 'telegram/validate-token';
     65                    console.log('[CNVRSE DEBUG] Calling API:', apiUrl);
     66                    console.log('[CNVRSE DEBUG] Nonce:', cnvrseSettings.nonce);
     67
    4768                    // Validate bot token via REST API
    4869                    fetch(
    49                         cnvrseSettings.apiUrl + 'telegram/validate-token',
     70                        apiUrl,
    5071                        {
    5172                            method: 'POST',
     
    5980                    .then(
    6081                        function (response) {
    61                             return response.json(); }
     82                            console.log('[CNVRSE DEBUG] Response status:', response.status);
     83                            console.log('[CNVRSE DEBUG] Response ok:', response.ok);
     84                            console.log('[CNVRSE DEBUG] Response headers:', [...response.headers.entries()]);
     85                            return response.json();
     86                        }
    6287                    )
    6388                    .then(
    6489                        function (data) {
     90                            console.log('[CNVRSE DEBUG] Response data:', JSON.stringify(data, null, 2));
     91
    6592                            if (data.success) {
    66                                 botUsername    = data.data.bot_username || '';
     93                                console.log('[CNVRSE DEBUG] Token validated successfully!');
     94                                // Handle both response formats: {data: {bot_username}} or {bot_username}
     95                                var responseData = data.data || data;
     96                                botUsername    = responseData.bot_username || '';
     97                                var botName    = responseData.bot_name || '';
    6798                                validatedToken = token;
     99                                console.log('[CNVRSE DEBUG] Bot username:', botUsername, 'Bot name:', botName);
    68100
    69101                                // Bot validated, now auto-detect chat ID
    70102                                helper.textContent = cnvrseAdminParams.i18n.lookingForChatId;
    71103
     104                                console.log('[CNVRSE DEBUG] Now detecting chat...');
    72105                                fetch(
    73106                                    cnvrseSettings.apiUrl + 'telegram/detect-chat',
     
    83116                                    .then(
    84117                                        function (response) {
    85                                             return response.json(); }
     118                                            console.log('[CNVRSE DEBUG] Chat detect response status:', response.status);
     119                                            return response.json();
     120                                        }
    86121                                    )
    87122                                    .then(
    88123                                        function (chatData) {
    89                                             if (chatData.success) {
    90                                                 var chatId        = chatData.data.chat_id;
     124                                            console.log('[CNVRSE DEBUG] Chat detect data:', JSON.stringify(chatData, null, 2));
     125                                            // Handle both response formats: {success: true, chat_id} or {chat_id}
     126                                            var chatResponseData = chatData.data || chatData;
     127                                            var chatId = chatResponseData.chat_id;
     128
     129                                            // Check if we got a chat_id (success) or an error
     130                                            if (chatId) {
     131                                                console.log('[CNVRSE DEBUG] Chat ID found:', chatId);
    91132                                                chatIdInput.value = chatId;
    92133
    93134                                                // Save settings and show connected state
    94                                                 saveAndReload( token, chatId, data.data.bot_name, botUsername );
     135                                                saveAndReload( token, chatId, botName, botUsername );
    95136                                            } else {
    96137                                                // No chat found - show "Open in Telegram" button
    97                                                 showOpenTelegramFlow( data.data.bot_name, botUsername );
     138                                                console.log('[CNVRSE DEBUG] No chat found, showing QR flow');
     139                                                showOpenTelegramFlow( botName, botUsername );
    98140                                            }
    99141                                        }
    100142                                    )
    101143                                    .catch(
    102                                         function () {
     144                                        function (err) {
     145                                            console.error('[CNVRSE DEBUG] Chat detect error:', err);
    103146                                            resetToEmpty( cnvrseAdminParams.i18n.connectionError );
    104147                                        }
     
    106149                            } else {
    107150                                // Token validation failed
    108                                 resetToEmpty( data.data || cnvrseAdminParams.i18n.invalidToken );
     151                                console.error('[CNVRSE DEBUG] Token validation FAILED:', data);
     152                                var errorMsg = data.message || (data.data && data.data.message) || data.data || cnvrseAdminParams.i18n.invalidToken;
     153                                console.error('[CNVRSE DEBUG] Error message:', errorMsg);
     154                                resetToEmpty( errorMsg );
    109155                            }
    110156                        }
    111157                    )
    112158                    .catch(
    113                         function () {
     159                        function (err) {
     160                            console.error('[CNVRSE DEBUG] Fetch error:', err);
     161                            console.error('[CNVRSE DEBUG] Error name:', err.name);
     162                            console.error('[CNVRSE DEBUG] Error message:', err.message);
     163                            console.error('[CNVRSE DEBUG] Error stack:', err.stack);
    114164                            resetToEmpty( cnvrseAdminParams.i18n.connectionError );
    115165                        }
     
    184234                    .then(
    185235                        function (chatData) {
    186                             if (chatData.success) {
     236                            // Handle both response formats
     237                            var chatResponseData = chatData.data || chatData;
     238                            var chatId = chatResponseData.chat_id;
     239
     240                            if (chatId) {
    187241                                clearInterval( pollInterval );
    188                                 var chatId        = chatData.data.chat_id;
    189242                                chatIdInput.value = chatId;
    190243
     
    257310
    258311        function resetToEmpty(errorMsg) {
     312            console.log('[CNVRSE DEBUG] resetToEmpty called with:', errorMsg);
    259313            tokenInput.classList.remove( 'cnvrse-telegram-field__input--validating' );
    260314            connectBtn.classList.remove( 'cnvrse-telegram-field__btn--validating' );
  • cnvrse/trunk/cnvrse-lite.php

    r3426548 r3426979  
    44 * Plugin URI: https://cnvrse.com/cnvrse-lite
    55 * Description: Cnvrse Lite is a simple, privacy-friendly live chat widget for WordPress. Reply to your visitors directly from your WordPress Admin or from Telegram. No external accounts required.
    6  * Version: 025.12.23.07
     6 * Version: 025.12.24.01
    77 * Author: cnvrse
    88 * Author URI: https://profiles.wordpress.org/cnvrse/
     
    2222
    2323
    24 define( 'CNVRSE_VERSION', '025.12.23.07' );
     24define( 'CNVRSE_VERSION', '025.12.24.01' );
    2525define( 'CNVRSE_FILE', __FILE__ );
    2626define( 'CNVRSE_DIR', plugin_dir_path( __FILE__ ) );
  • cnvrse/trunk/readme.txt

    r3426548 r3426979  
    55Tested up to: 6.9
    66Requires PHP: 7.4
    7 Stable tag: 025.12.23.07
     7Stable tag: 025.12.24.01
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
  • cnvrse/trunk/src/REST/Controllers/class-cnvrse-rest-telegram-controller.php

    r3426494 r3426979  
    211211     *
    212212     * @param WP_REST_Request $request Request object.
    213      * @return WP_REST_Response
    214      */
    215     public function detect_chat( WP_REST_Request $request ): WP_REST_Response {
     213     * @return WP_REST_Response|WP_Error
     214     */
     215    public function detect_chat( WP_REST_Request $request ): WP_REST_Response|WP_Error {
    216216        $token = $this->get_string_param( $request, 'token' );
    217217
Note: See TracChangeset for help on using the changeset viewer.