Appwrite Games ( With Telegram Bot )

Appwrite, Hashnode Hackathon

Thankyou Appwrite and Hashnode for this opportunity

Check out this project on builtwith Appwrite https://builtwith.appwrite.io/projects/6489c5fbc174784f1a32/

Team Details

Description of project

This is a Flutter application with multiple games like Chess, Snake, Dino

and uses Appwrite for real-time communication including a proper Authentication system, and we also have a Telegram Bot

This Bot can do multiple things like

  • Using OpenAI for chatting

  • Using OpenAI for generating images

  • We can play Those Games directly inside Telegram app with the help of FlutterWeb and TelegramWeb

  • Get the scoreboard of the games

So this app is not just limited to Mobile/Desktop or Web, we can also use this inside the telegram bot, and this Telegram bot is running on Appwrite CloudFunctions with Dart environment

Tech Stack

Frontend: Flutter

Supported Platforms: Android, IOS, Web, MacOS, Windows, Linux, TelegramWebApp

Database: Appwrite Database ( For real-time communications in Playing chess and for storing the scores of users for Snake or other games )

Authentication: Appwrite Auth ( Email Session ) for authenticating users

TelegramBot: Appwrite Cloud Functions ( For TelegramBot message handeling as well as OpenAI operations )

Language Used: Dart ( For cloud Functions as well as Flutter )

Sample web app hosted on: Github Pages

Challenges we faced

Well there were many challenges while building this project, let's Discuss them one by one

  • There was no way to host a Telegram bot on Appwrite cloud functions because we can't rely on polling and we can't handle the webhook of Telegram directly, so I built a proxy that will work as a middleware to get data from Telegram and pass it to Appwrite ( This workaround will not be needed anymore in future because Appwrite is planning to support webhooks handling in upcoming updates ), but for now, if someone wants to set up that proxy using Deta with my prebuilt instance of AppwritePing, check details in my repo, it's free and just a single click to set up

    https://github.com/rohitsangwan01/appwrite_webhook_deta

    There is another workaround using railway, check out this repo

    Ahh btw with this proxy, I have created Telegram Bot samples in multiple languages, Check out this repo for building bots in Javascript, Dart, Python, and PHP so we can choose our preferred language and pick any template to run the bot

    https://github.com/rohitsangwan01/appwrite_telegram_bot


  • Another hurdle was that Appwrite cloud functions currently supports Dart 2.17, and most of the libraries I required were not supporting older Dart versions, so the only option was to use a different language like Python, js etc.. but because I was writing the main app in Dart, so I wanted the cloud functions in dart too, to share the business logic and hence I fixed this by creating forks of those libraries with lower Dart SDK and required changes, here are dependencies i used: https://github.com/rohitsangwan01/appwrite_games/blob/main/appwrite_bot/functions/appwrite_bot/pubspec.yaml#L11-L20

  • Another hurdle was to run the Flutter web app on Telegram because I wanted to create a gaming ecosystem within Telegram so that friends can play there and track scores without leaving Telegram app, so for this I created a library for running the FlutterWeb app on TelegramWeb, and here is my another opensource library which can run flutter apps on TelegramWeb

    https://github.com/rohitsangwan01/flutter_telegram_web_app


  • Another plan was to run a WhatsApp bot as well, and for that, i prepared my another library to run on a pure dart environment, but WhatsApp bot can't run on serverless for now, but I will find a way to run this, had to drop this plan because of time limitations, here is my repo if someone wants to give it a try

    https://github.com/rohitsangwan01/whatsapp_bot_flutter

So yeah, these were the challenges I faced which resulted in some cool open-source libraries and repositories which I hope will be useful for the community too

Code Repository

Extra Resources

Demo App

Appwrite Games web app

https://rohitsangwan01.github.io/appwrite_games_web/

Appwrite Games android app

https://github.com/rohitsangwan01/appwrite_games/blob/main/appwrite_games.apk

Telegram Bot

https://t.me/appwrite_bot

Demo Screenshots and Recording

Here is a demo video of this project

https://youtu.be/cknFVQhVgh0

Telegram WebApp ( IOS + MacOS )

Responsive Web

Thank you so much for reading this article, I will try to add more games and features to this project

#Appwrite #AppwriteHackathon