Giter VIP home page Giter VIP logo

Comments (9)

atipugin avatar atipugin commented on June 12, 2024

Hi @antondgx,

Yes, web apps are supported

from telegram-bot-ruby.

antondgx avatar antondgx commented on June 12, 2024

That is very cool and quick update! Thank you for building and maintaining this gem!

Im trying to figure out how to open the web app via inline button. below is a sample code. can you let me know what is wrong? "../web_app.html.erb" is the html file that i want to display. It gives this error: "uninitialized constant Telegram::Bot::Types::WebAppInfo (NameError)"

Sample code:
def test(user, message_obj)
final_obj = check_message_type(message_obj)
web_app_info = Telegram::Bot::Types::WebAppInfo.new(url: "../web_app.html.erb")

Telegram::Bot::Client.run(@token) do |bot|
  bot.api.editMessageText(chat_id: final_obj["chat"]["id"], message_id: final_obj["message_id"], text: "Goodbye #{user.first_name}! Press /start to start again", web_app: web_app_info)
end

end

from telegram-bot-ruby.

antondgx avatar antondgx commented on June 12, 2024

below line gives this error: "uninitialized constant Telegram::Bot::Types::WebAppInfo (NameError)". I cant figure out whats wrong. "http://localhost:3000/web_app.html" is a html in my rails application. Can anyone help?

web_app_info = Telegram::Bot::Types::WebAppInfo.new(url: "http://localhost:3000/web_app.html")

from telegram-bot-ruby.

atipugin avatar atipugin commented on June 12, 2024

Have you updated gem up to the recent version?

from telegram-bot-ruby.

antondgx avatar antondgx commented on June 12, 2024

Hey, Thanks! Indeed the gem is not updated. After i installed the latest version there is no more error. However there is no reaction from my bot when I press inline button on my bot to display the intended html page. Any idea what is the problem? how do i connect the backend with the html page? Below are my sample codes:

backend code (a function in my bot logic):

  def bye(user, message_obj)
    final_obj = check_message_type(message_obj)
    Telegram::Bot::Client.run(@token) do |bot|
      web_app_info = Telegram::Bot::Types::WebAppInfo.new(url: "https://604d-27-125-173-138.ap.ngrok.io/web_app")
      kb = [Telegram::Bot::Types::InlineKeyboardButton.new(text: "WEB APP!!", web_app: web_app_info)]
      markup = Telegram::Bot::Types::InlineKeyboardMarkup.new(inline_keyboard: kb)
      bot.api.send_message(chat_id: final_obj["chat"]["id"], message_id: final_obj["message_id"], text: "Open Web App!!", reply_markup: markup)
    end
  end

HTML code (web_app.html):

<html>
  <head>
    <meta charset="utf-8">
    <title>Test</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, user-scalable=no, viewport-fit=cover" />
    <meta name="format-detection" content="telephone=no" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="MobileOptimized" content="176" />
    <meta name="HandheldFriendly" content="True" />
    <meta name="robots" content="noindex, nofollow" />
    <script src="https://telegram.org/js/telegram-web-app.js"></script>
    <script>
      function setThemeClass() {
        document.documentElement.className = Telegram.WebApp.colorScheme;
      }
      Telegram.WebView.onEvent('theme_changed', setThemeClass);
      setThemeClass();
    </script>
  </head>

  <body>
    <h1> HELLO WORLD </h1>
  </body>
</html>

from telegram-bot-ruby.

antondgx avatar antondgx commented on June 12, 2024

Can Anyone help? Thanks

from telegram-bot-ruby.

atipugin avatar atipugin commented on June 12, 2024

@antondgx i haven't tried web apps yet, gonna give it a try this weekend

from telegram-bot-ruby.

antondgx avatar antondgx commented on June 12, 2024

Awesome! I look forward for some guidance for this. This will be such a game changer for telegram bots in future!

from telegram-bot-ruby.

atipugin avatar atipugin commented on June 12, 2024

Looks like it's an issue with Telegram Desktop app. Following code works just fine in web (https://web.telegram.org) and mobile app, but indeed doesn't work on desktop.

def handle_message(api, message)
  web_app = Telegram::Bot::Types::WebAppInfo.new(url: 'https://google.com')
  kb = [[Telegram::Bot::Types::InlineKeyboardButton.new(text: 'Open Web App', web_app: web_app)]]
  markup = Telegram::Bot::Types::InlineKeyboardMarkup.new(inline_keyboard: kb)
  api.send_message(chat_id: message.chat.id, text: 'Hey!', reply_markup: markup)
end

Telegram::Bot::Client.run(token) do |bot|
  bot.listen do |message|
    case message
    when Telegram::Bot::Types::Message
      handle_message(bot.api, message)
    end
  end
end

Btw regular KeyboardButton works in desktop app too.

from telegram-bot-ruby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.