Jump to content

Submitting score from html5 game that can run on telegram server.


Solserv
 Share

Recommended Posts

Hello,

I recently develop a game in html5 and upload it to run on telegram. 

 

But I am not able to use the function setgamescore to submit the score on telegram server. 

I am using Ajax to post the score.

 

Please If any one had any idea what I am doing wrong. Please help.

 

Thank you 

Link to comment
Share on other sites

This is the code I am using in my game to send the score to telegram and I am 400 error bad request.

var api_url = "https://api.telegram.org/bot";
var token = "593511496:AAFE92jjNdWSsWfUMT8PCSAqmOVYCohqzBc";

api_url += token;

var userId;
var chatId;
var messageId;

var xhttp = new XMLHttpRequest();

function init() {

    console.log (window.TelegramGameProxy.initParams);

    userId = parseInt(window.TelegramGameProxy.initParams.userId);
    chatId = parseInt(window.TelegramGameProxy.initParams.chatId);
    messageId = parseInt(window.TelegramGameProxy.initParams.messageId);

    console.log (userId);
    console.log (chatId);
    console.log (messageId);
    
    xhttp.onreadystatechange = function () {

        if (this.readyState == 4 && this.status == 200) {
            var data = JSON.parse(this.responseText);
            console.log (data);
        }
    }

    api_url = api_url + "/setGameScore?user_id=" + userId + "&chat_id=" + chatId + "&message_id=" + messageId + "&score=" + score + "&inline_message_id=";
    console.log (api_url);

    xhttp.open ( "POST", api_url, true);
    xhttp.send();
    
}

Hope this will be helpful for you.

 

Thanks

Link to comment
Share on other sites

12 hours ago, Solserv said:

I tried the same code with get me function that return some basic information. 

It works successfully. Also when I tried the onerror. It display bad request. 

You are saying that request is not proper to reach out. 

 

I didn't say to reach out, just it's not right, it also can be because of bad parameters which server-side can't handle or accept. Did you try to post JSON data instead of query? Did you try to use GET method?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...