How to adapt HTML5 games to be published on Telegram

The Announcement

On October 3rd, Telegram published its gaming platform. Now, the bots are able to launch HTML5 games inside Telegram and share your score with your friends. @gamebot and @gamee were the two first bots announced and Ludei is not going to be the last when it comes to HTML5.

The Rules

When creating a game with @BotFather, he will make you accept a series of rules:

  1. You will not implement any ads or any external links on your custom URL pages.
  2. You will not invite users to pay for any services provided on custom URL pages.
  3. You will not use any data collected over the course of user interaction with your custom URLs for spamming Telegram users.
  4. You will not transfer any Telegram data collected over the course of user interaction with your custom URLs to any third parties.
  5. In order to protect the privacy of Telegram users, your custom URL pages must not set any cookies.

Now, those are some serious rules that made us change some things in our games.

Due to these rules we had to remove every way of promoting the rest of our games and every social media integration like Twitter or Facebook. Thankfully, we didn’t collect any information for third parties neither used cookies in our games -removing all that sounds like a headache.

Game Rules by @BotFather

Game rules by @BotFather

Sharing the games

The first thing you notice when reading the technical post is the script you have to include inside your games. It is a rather short script. This is because launching a game inside Telegram means opening a URL, provided by our bot, in the webview of Telegram. Our game should need hardly any changes.

<script src="https://telegram.org/js/games.js"></script>

This script provides us with the TelegramGameProxy.shareScore() method, which is used to share the game (but not a score, weird) with Telegram chats. It works like the usual share button in Telegram, there is no complexity with this part. We added a button with the shareScore() function at the result screen of each game in case you don’t know what to do with it.

Sending scores

The name “shareScore“ is quite confusing since you can’t even pass it a parameter to share. To actually send a score you should also read our post about a game bot creation. The game must send the score to the bot (with a HTTP POST, in our case) and the bot is responsible of notifying Telegram of our score. But how does the bot know who we are when it receives it? We solved this problem sending along the score a number of identifiers the bot previously added to the URL of the page. These identifiers are always userId (identifies the user) and either inlineId (if the bot was summoned with an inline call), or the pair chatId and messageId. The necessary ones are in the request Telegram sends to our bot when a user taps the play button.

Update scores in Telegram

@ludeiBot updates scores in Telegram

To sum it up: the user activates the play button, Telegram asks our bot for a URL to open and sends the identifications of the user, the bot returns a URL containing those identifiers in a query, and finally, our game can send the score and the identifiers of the user so the bot can update the rankings.

Detecting Telegram

At this point we have a game that can be published to Telegram, but why would we use two versions of the source code of our game? We still want to be able to promote our games if the user plays at ludei.net. If we can know when the game is executing as a Telegram game we can serve it from its original server to Telegram. Any special change we made for Telegram just has to follow a condition.

At first we tried checking window.TelegramWebviewProxy !== undefined  (like Telegram does in its script), but somehow TelegramWebviewProxy is undefined even inside the Telegram webview, so in the end, we just check if the URL contains the identifiers of Telegram our bot adds. In our case the identifiers were query parameters because our games already had a method to parse them. Although they could have been hash parameter too; Telegram exposes an object containing them.

Testing your game

The last thing to do is testing. Most of the testing can be done easily like with any web page development: set up a local server and open the URL in your devices. But we found some resolution problems when Telegram launched the games. Some elements appeared several times larger than when using a typical browser app. Therefore, one last advice from us is to create a minimal test bot, capable of just launching the games, enough to be able to fix any bug that might appear only in Telegram.

Our games

Check out our games (please open the following links on your mobile device):

42 Comments How to adapt HTML5 games to be published on Telegram

  1. avatarJordan

    After that after that it guaranteed, try and earn although
    except there is money on offer likewise your task is done if you have guaranteed diploma.

    Reply
  2. avatarRomi

    Hello,

    I developed a game and adapt it to telegram. I am not able to setgamescore

    It shows bad request error.

    I tried to post the score using api + token + setGameScore?user_id=&chatId=&messageId=

    But not able to store the score on telegram.

    Please help I am not able to do this from past 2 weeks.

    I will wait for your response.

    Thank you

    Reply
  3. avatarhp customer support

    It is not so easy to develop the game with a lot of efforts and the hue which is very much essential to make the best one and then it is going to be in user’s hand to play it and for such things, it needs to adapt the html5 process to get in telegram perfectly.

    Reply
  4. avatarHP Printer Support

    I am happy to be here and this wonderful article. I have found here lots of interesting information for my knowledge I need. all the details you provide to us, it was very helpful and useful, thanks for sharing this amazing post.

    Reply
  5. avatarHP Printer Help

    Oh Superb post, please keep up posting some related topic. I am waiting for your next update. If you are want to some type of support/information then visit the HP printer support website.
    Thanks

    Reply
  6. avatarHP printer offline windows 10

    I like your way of writing so I read your content as much as possible and one more thing I like your topic also. So thanks for all this. If you are facing some kind of problem with printer in contact with us through our HP printer offline windows 10 website page.
    Thanks

    Reply
  7. avatarSupport Yahoo Help

    Steps to restore contacts from Yahoo Mail to Android phone

    • The first step is to add Yahoo Mail to your mobile device
    • Now, open your device’s Settings section
    • Here, tap on Accounts option
    • Now, you need to tap on Yahoo option
    • Here tap on your Yahoo Mail account
    • Then, select Sync Contacts to turn it on in order to restore on your device
    • That’s all

    Reply
  8. avatarLimos by Harry

    Thanks for the advice. it so interesting and informative post. I will definitely use the tips. If you are willing to ride a limo, Book the Limos By Harry in Fremont, Chicago, Oakland, Santa Cruz, Santa Cruz, Los Gatos then you may visit our website and go through our special plans for limos.

    Reply
  9. avatarcomputer support

    Any interference in your IT framework at working environment can be exceptionally chafing. You remain to lose important time and business to your rivals.

    Be that as it may, there is no compelling reason to stress if and when this occurs. Quick and authentic computer IT support is available to you with just a phone call.

    Reply
  10. avatarCharlie William

    Get Certified Online Help for Roadrunner Email

    Roadrunner email is a famous email service used all over the world to send/receive emails. There may be a possibility of having technical issue with the roadrunner email like login issue, forget password and much more. You can get help by contacting Roadrunner Support Phone Number to resolve all the issues related to Roadrunner email.

    Reply
  11. avatarBestBernardo

    I see you don’t monetize ludei.com, don’t waste your traffic, you can earn additional cash every month with new monetization method.

    This is the best adsense alternative for any type
    of website (they approve all sites), for more details simply search in gooogle: murgrabia’s tools

    Reply
  12. avatarEpson Printer Support

    Does your printing job is interrupted by Epson Error Code 0XF1? Well if so, then you don’t need to panic, you can get the proper solution at your fingertips. The Epson printer Error 0XF1 is a very critical error that you encounter within your Epson Printer. This error restricts your printer to accomplish a printing command sent by the computer. This crops up mainly due to the entry of damage registry in your computer. When you turn your Epson printer on, the printer head is unable to read either from the left side or from the right side or while it is initiating the printing process. Anyhow, you have to terminate this error code if you want to print your documents.
    https://www.epsonprintersupportpro.us/epson-error-code-0xf1

    Reply
  13. avatarElla Bai

    Kaspersky is one of the globally recognized security service providers, which is mainly designed for Windows and MAC OS. Kaspersky helps in keeping our devices free from viruses, malware, spyware, phishing attacks, and various other threats. It not only protects the device but further it detects the threat beforehand and notify us. To get Kaspersky technical support, dial Kaspersky Customer Care Number.
    https://www.onlinesupportpro.us/kaspersky/

    Reply
  14. avatarMICHAELS johnson

    Get help from experts for Canon printer setup
    Wondering how to configure a new printer on your iPhone, iPad, iPod Touch or Android mobile device? Just download the Canon PRINT App, hit your printer’s Wireless Connect button and the data stored on your phone, including your Wi-Fi name and password, will automatically be shared allowing the overall setup process quicker and easier than ever. There are different methods to set up the canon printer in different versions of the printer. If you want to know the Canon printer setup guide, contact our experts. They will give you the easiest steps to do so. Just dial our toll-free number and talk with the experts. The best part is that you can call round the clock.

    Reply
  15. avatarTelus Support

    If You are facing problem in creating Telus email account, recover forgotten Telus account password, Telus email has stopped working or any other issues etc. The support team of TELUS provides you the guaranteed support for your issues. All you have to do is dial our TELUS SUPPORT PHONE NUMBER and get your issues resolved.

    Reply
  16. avatarMcafee.Com/Activate

    Is your McAfee Antivirus expired or about to expire? Then it is the right time to act fast to activate your antivirus as quickly as possible. In the times of harmful virus attacks and cyber-attacks, it is significant to keep your system safe and running. Therefore, it is better to adapt the ways to activate, as not doing so will surely make your system vulnerable against various threats. If you are not acquainted with the right procedure for activating McAfee antivirus, then you should visit Mcafee.Com/Activate or consider taking help from McAfee support team. At here, you will get the chance to meet with deft team of technicians who will assist you out in doing the needful.

    Reply
  17. avatarPrinter Repair

    It is a written message transmitted by using an electric device. The message was carried along wires, and the text written or printed and delivered by hand or teleprinter. Telegrams were very widely used because private telephones were not usual.

    Reply
  18. avatarHP Bios update

    If someone is looking to improvise the version of his device than it is necessary for him to get HP bios update as soon as possible. For more details you can also visit HP Bios update.

    Reply
  19. avatarBuy Bitcoin

    If you are interested in investment in bitcoins then it is the right place for you to buy Bitcoins. We provide one of the best and reliable services to our customers when it comes to trade in cryptocurrency.

    Reply
  20. avatarJason Assistant

    While working on a computer sometimes one has the need to get the screenshot of the current window to get the screenshot one must know about how to take a screenshot on the HP laptop. If you also want to know about how to take a screenshot then you must follow the link mentioned here.

    Reply
  21. avatarJOHNPOCUS

    Brother Support Service: Correct The Improper Installation Of Brother Printer
    Yes it’s true! Brother Support service which help you to correct the improper installation. In such a case, you should opt for the correct guidance and supervision. Here, you will surely get the correct assistance so that you could install the Brother Printer Offline in a correct manner. https://www.brotherprintersupportpro.net/

    Reply
  22. avatarHP Printers Support

    Millions of HP printers are delivering good quality printouts to their users. If you have any query regarding HP printers then reach HP Printers Support via phone, email and chat. You will get complete solution from experts to fix technical issues related to HP devices.

    Reply
  23. avatarsbcglobal yahoo email

    Got a problem in your sbcglobal yahoo email settings and also want to update it. You can have it both- Settings and Update process on our website. If you enter our website on URL, you get all kind solutions related to Yahoo sbcglobal Net Email problems. But if, you are looking for tech assistance.

    Reply
  24. avatarFacebook Marketplace

    Increase Sales For Your Product| live Chat For Facebook Marketplace
    Facebook marketplace is an effective tool in promoting your business but only when it is used in a right way. Communicating with experts for Facebook is considered as the best option. The professional team will guide you through all the effective strategies, making an attractive page so that every person land on your Facebook page and make regular visits.

    Reply
  25. avatarFacebook Account Recovery

    What Is The Correct Facebook Account Recovery Solution?

    Facebook Account Recovery is a simple operation of recovering the lost Facebook account password. What you need to do is to verify the online identity by using alternative email address and phone number. You can get your account password recovered within a least time frame and regain access to your account.

    Reply

Leave a Reply to Support Yahoo Help Cancel reply

Your email address will not be published. Required fields are marked *