Keyboards #11

Closed
opened 2015-09-30 23:21:33 +00:00 by Behnamgh · 3 comments
Behnamgh commented 2015-09-30 23:21:33 +00:00 (Migrated from github.com)

how to set a custom keyboard with this package?
we must define keyboard on every message that i recieve?

how to set a custom keyboard with this package? we must define keyboard on every message that i recieve?
mdibaiee commented 2015-10-01 05:56:59 +00:00 (Migrated from github.com)

Hey, do you want to set a global keyboard? Something like this would do:

const kb = new Keyboard().keys(['Hey', 'Test']);
const globalMessage = new Message().keyboard(kb);

bot.get(/Hello/, message => {
  bot.send(globalMessage.msg('Hey'));
});

bot.get(/Test/, message => {
  bot.send(globalMessage.msg('This is a test'));
});

So you define a message with your global keyboard and for each response, you only change the message/other properties. If you don't like this approach, you can make something yourself like:

function msg() {
  return new Message().keyboard(kb);
}

So now instead of creating messages using new Message, you use msg() which always sets your global keyboard, the second appraoch is more reliable, so I recommend it.

Hey, do you want to set a global keyboard? Something like this would do: ``` javascript const kb = new Keyboard().keys(['Hey', 'Test']); const globalMessage = new Message().keyboard(kb); bot.get(/Hello/, message => { bot.send(globalMessage.msg('Hey')); }); bot.get(/Test/, message => { bot.send(globalMessage.msg('This is a test')); }); ``` So you define a message with your global keyboard and for each response, you only change the message/other properties. If you don't like this approach, you can make something yourself like: ``` javascript function msg() { return new Message().keyboard(kb); } ``` So now instead of creating messages using `new Message`, you use `msg()` which always sets your global keyboard, the second appraoch is more reliable, so I recommend it.
Behnamgh commented 2015-10-01 08:33:01 +00:00 (Migrated from github.com)

agha dame shoma garm,hal dadi.packagetam alie!tabrik migam be tavanaiiiit

agha dame shoma garm,hal dadi.packagetam alie!tabrik migam be tavanaiiiit
mdibaiee commented 2015-10-01 10:43:54 +00:00 (Migrated from github.com)

@Behnamgh: Khoshhalam be karet oomad 😁, mamnoon ✌️

@Behnamgh: Khoshhalam be karet oomad 😁, mamnoon ✌️
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: thereadme/node-telegram-api#11
No description provided.