Comments (9)
Hi @antondgx,
from telegram-bot-ruby.
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.
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.
Have you updated gem up to the recent version?
from telegram-bot-ruby.
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.
Can Anyone help? Thanks
from telegram-bot-ruby.
@antondgx i haven't tried web apps yet, gonna give it a try this weekend
from telegram-bot-ruby.
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.
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)
- AnswerInlineQuery not work correctly HOT 2
- undefined method `from' for nil:NilClass (NoMethodError) HOT 3
- How to read channel messages?
- Forward message with images HOT 1
- User chats HOT 1
- Get list of join request to channel
- ArgumentError if message is not a string HOT 3
- Question. How do i listen only new message after bot was started? HOT 2
- How to receive Voice messages? HOT 1
- Periodic Net::ReadTimeout errors causing restart for 24/7 Bot HOT 3
- Support for ChatMember types HOT 4
- Add VCR for specs HOT 1
- `ForceReply#force_reply` type and optionality HOT 1
- Return defined types (Ruby objects) HOT 3
- Update `thumb` fields to `thumbnail`
- Webhooks empty ChatMember HOT 2
- TERM trap does not work anymore as in README HOT 5
- Uploading large files with local API causes Net::ReadTimeout with #<TCPSocket:(closed)> HOT 1
- Message.text is nil even thought the schema says it can not be HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from telegram-bot-ruby.