deptyped / vue-telegram

Telegram integration for Vue
https://vue-tg.pages.dev
MIT License
91 stars 6 forks source link

canSendData not working #23

Closed johnedstone closed 1 week ago

johnedstone commented 2 weeks ago

Here is the output of this code:

<template>
  <p>initData: {{ initData }}</p>
  <p>initDataUnsafe: {{ initDataUnsafe }}</p>
  <p>isPlatform: {{ isPlatform }}</p>
  <p>isPlatformUnknown: {{ isPlatformUnknown }}</p>
  <p>isReady: {{ isReady }}</p>
  <p>canSendData: {{ canSendData }}</p>
  <p>platform: {{ platform }}</p>
  <p>version: {{ version }}</p>
</template>

MiniApp output query_id=AAHxw2** initDataUnsafe: { "query_id": "AAHxw2 } isPlatform: e=>Telegram.WebApp.platform===e isPlatformUnknown: false isReady: false canSendData: false platform: android version: 7.2

Why is "canSendData" false? Shouldn't this line of your code say ``Telegram.WebApp.initData !=""?

const canSendData = !isPlatformUnknown && Telegram.WebApp.initData === ""
deptyped commented 2 weeks ago

This is a Telegram limitation, you can only use Telegram.WebApp.sendData if the web app was launched from custom keyboard: https://core.telegram.org/bots/webapps#keyboard-button-mini-apps Telegram.WebApp.initData === "" is the way to check this.

johnedstone commented 2 weeks ago

I did in fact launch it from a Keyboard Button Mini Apps launched from a web_app type keyboard button can send data back to the bot in a service message....To transmit data from the user back to the bot, the Mini App can call the Telegram.WebApp.sendData method) which is the only way that allows for Telegram.WebApp.sendData with the following code from the telethon library:

async def web_app_button(event):
        bl = types.ReplyInlineMarkup([
            types.TypeKeyboardButtonRow([
                types.KeyboardButtonWebView('Test!', WEB_URL),
            ])])

        await event.respond("Open URL below", buttons=bl)

Shouldn't you be checking that there is, in fact, a string in Telegram.WebApp.initData?

deptyped commented 2 weeks ago

types.ReplyInlineMarkup

As I can see you are using inline keyboard, this is a different type of keyboard and it does not support Telegram.WebApp.sendData. You need to use types.ReplyKeyboardMarkup to send custom keyboard.

johnedstone commented 2 weeks ago

Thanks. Did I read the Telegram documentation incorrectly, or is this an implementation of your library? Thanks again.

On Sat, May 18, 2024, 7:42 PM deptyped @.***> wrote:

types.ReplyInlineMarkup

As I can see you are using inline keyboard https://core.telegram.org/bots/webapps#inline-button-mini-apps, this is a different type of keyboard and it does not support Telegram.WebApp.sendData. You need to use types.ReplyKeyboardMarkup to send custom keyboard.

— Reply to this email directly, view it on GitHub https://github.com/deptyped/vue-telegram/issues/23#issuecomment-2119031425, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABI3LM7PLNRPPOA7SATABF3ZC7RN7AVCNFSM6AAAAABH5YITB6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJZGAZTCNBSGU . You are receiving this because you authored the thread.Message ID: @.***>

deptyped commented 2 weeks ago

This limitation is documented in the description of the sendData method:

IMG_20240519.jpg

https://core.telegram.org/bots/webapps#initializing-mini-apps

johnedstone commented 2 weeks ago

Let me reread... thanks!

On Sat, May 18, 2024, 9:02 PM deptyped @.***> wrote:

This limitation is documented in the description of the sendData method:

IMG_20240519_040053_116.jpg (view on web) https://github.com/deptyped/vue-telegram/assets/26162440/3a376630-b448-4de3-9db9-e4edb97bb46a

https://core.telegram.org/bots/webapps#initializing-mini-apps

— Reply to this email directly, view it on GitHub https://github.com/deptyped/vue-telegram/issues/23#issuecomment-2119048350, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABI3LM375WGGJEFPGUSHHLTZC722RAVCNFSM6AAAAABH5YITB6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJZGA2DQMZVGA . You are receiving this because you authored the thread.Message ID: @.***>

johnedstone commented 2 weeks ago

... yes, I've mixed up the two ... thank you.... if I continue to use the inline button, did you implement Bot API method answerWebAppQuery that can be used with an inline button?

deptyped commented 1 week ago

answerWebAppQuery is part of the Bot API and vue-tg is not a Bot API library, so you need some Bot API library like aiogram to use this method: https://docs.aiogram.dev/en/dev-3.x/api/methods/answer_web_app_query.html

List of libraries for Python to work with Bot API: https://core.telegram.org/bots/samples#python

deptyped commented 1 week ago

But if you are looking for a way to pass data from web app to bot, answerWebAppQuery method is not what you need. For non-replykeyboard web apps, you need to send a POST request to server to transfer data, just like in a normal (non-Telegram) web app.

johnedstone commented 1 week ago

Okay thanks .... I need to reread the docs. You've cleared some things up for me. Thanks again. I think that you can close this issue..