Comments (7)
Hi @a-fatah
This doesn't seem to be a problem with telegram-keyboard
. If you do console.log(mainMenuKeyboard)
you will see that reply_markup
looks good. Does this error appear if you remove the use of telegram-keyboard
? And what version of Telegraf?
from telegram-keyboard.
I could explain the reason if I wrote better in English 😄
But now I see that you are using [email protected] version. So, in [email protected] you cannot be destructured methods from context (you must always write like this: (ctx) => ctx.reply('some')
. My examples written for [email protected] where you can write as you like, for example ({ reply }) => reply('some')
from telegram-keyboard.
When destructuring a method from the class, its execution context is lost and this
is no longer referenced to the current instance. And in this line https://github.com/telegraf/telegraf/blob/develop/src/context.ts#L264 this
is equal undefined
In [email protected] it was solved using bind
: https://github.com/telegraf/telegraf/blob/3.38.0/context.js#L68
You can play around with this small example to figure out what's the matter
class Context {
reply() {
console.log('this', this)
}
}
const ctx = new Context()
// 1
ctx.reply()
// 2
const { reply } = ctx
reply()
// 3
ctx.reply = ctx.reply.bind(ctx)
const { reply } = ctx
reply()
from telegram-keyboard.
Thanks @RealPeha
I figured it out. It wasn't really a problem with telegram-keyboard
. I am new in nodejs world so I think I made a funny mistake. Anyway I changed my code a little bit and it worked :)
Before
bot.start(({ reply }) => {
return reply("Simple Keyboard", mainMenuKeyboard);
});
After
bot.start(async (ctx) => {
await ctx.reply("Simple Keyboard", mainMenuKeyboard);
})
I would appreciate if you educate me what makes it different from the previous one.
PS I am a java developer who just started learning nodejs :)
from telegram-keyboard.
I just copy pasted the code from examples in this repository. I think you might want to update that file as well.
from telegram-keyboard.
I recommend using [email protected] because version 4 is currently unstable
install using npm
npm i [email protected] --save
or yarn
yarn add [email protected]
from telegram-keyboard.
Thank you so much for pointing me to right direction :)
But I can't understand why we can't use destructing in latest version ?
from telegram-keyboard.
Related Issues (20)
- SyntaxError: Unexpected token = HOT 3
- double click on inline buttons
- [HW/FR] Add mobile phone/current location request with callback HOT 5
- How to add one_time_keyboard field in Reply Keyboard HOT 3
- I have implemented an inline keyboard in my bot, but when I click on the button, the message with what is written on the button is not sent. HOT 1
- How to use HTML or Markdown HOT 1
- Write a good README
- Add more interesting examples
- How i can add "one_time_keyboard" option? HOT 1
- How to customize button text and reply HOT 3
- Limit access to admins only HOT 3
- Cannot deploy to heroku HOT 1
- Disable notifications from inline replies HOT 1
- Update options HOT 1
- Migrate to TypeScript HOT 1
- Buttons that open app on mobile HOT 1
- you have video for how to use this bot ?
- Keyboard as command
- customizing the buttons HOT 1
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-keyboard.