Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property data is does't exist on type CallbackQuery #1983

Closed
miruchigawa opened this issue May 1, 2024 · 2 comments
Closed

Property data is does't exist on type CallbackQuery #1983

miruchigawa opened this issue May 1, 2024 · 2 comments

Comments

@miruchigawa
Copy link

Context

I'm trying to get callback query data but typescript keep showing error data is doesn't exist

  • Telegraf.js Version: 14.16.3
  • Node.js Version: 22
  • Operating System: Arch Linux

Minimal Example Code Reproducing the Issue

... (ctx) => {
       const data = ctx.callbackQuery?.data.split(':')[1]
       console.log(data)
}

Expected Behavior

Current Behavior

Error Message and Logs (export DEBUG='telegraf:*')

Please include any relevant log snippets or files here.
@undermuz
Copy link

undermuz commented Jun 2, 2024

i have the same problem

@MKRhere
Copy link
Member

MKRhere commented Jun 2, 2024

Since callbackQuery can be a data or game callback, you need to narrow it.

import { callbackQuery } from "telegraf/filters";

// later
if (ctx.has(callbackQuery("data")) {
	const [ data ] = ctx.callbackQuery.data.split(":");
	// ...
}

@MKRhere MKRhere closed this as completed Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants