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

Fancy keyboard #60

Closed
gerardovf opened this issue Mar 25, 2017 · 3 comments
Closed

Fancy keyboard #60

gerardovf opened this issue Mar 25, 2017 · 3 comments

Comments

@gerardovf
Copy link

gerardovf commented Mar 25, 2017

Hi guidone,
In python I can create this nice keyboards:

HIGH_BRIGHTNESS_SYMBOL = "\U0001F506" # b'\xF0\x9F\x94\x86'
LOW_BRIGHTNESS_SYMBOL = "\U0001F505" # b'\xF0\x9F\x94\x85'
UPWARDS_BLACK_ARROW = "\U00002B06" # b'\xE2\xAC\x86'
DOWNWARDS_BLACK_ARROW = "\U00002B07" # b'\xE2\xAC\x87'
DOOR = "\U0001f6aa" # b'\xF0\x9F\x9A\xAA'
VERTICAL_TRAFFIC_LIGHT = "\U0001F6A6" # b'\xF0\x9F\x9A\xA6'
CAMERA = "\U0001F4F7" # b'\xF0\x9F\x93\xB7'

def setNormalKeyboard(cid):
markup = types.ReplyKeyboardMarkup()
itembtn11 = types.KeyboardButton(UPWARDS_BLACK_ARROW+"\nBlind #1")
itembtn12 = types.KeyboardButton(UPWARDS_BLACK_ARROW+"\nBlind #2")
itembtn13 = types.KeyboardButton(UPWARDS_BLACK_ARROW+"\nBlind #3")
itembtn14 = types.KeyboardButton(UPWARDS_BLACK_ARROW+"\nBlind #4")
itembtn15 = types.KeyboardButton(HIGH_BRIGHTNESS_SYMBOL+"\nON")
markup.row(itembtn11, itembtn12, itembtn13, itembtn14, itembtn15)
itembtn21 = types.KeyboardButton(DOWNWARDS_BLACK_ARROW+"\nBlind #1")
itembtn22 = types.KeyboardButton(DOWNWARDS_BLACK_ARROW+"\nBlind #2")
itembtn23 = types.KeyboardButton(DOWNWARDS_BLACK_ARROW+"\nBlind #3")
itembtn24 = types.KeyboardButton(DOWNWARDS_BLACK_ARROW+"\nBlind #4")
itembtn25 = types.KeyboardButton(LOW_BRIGHTNESS_SYMBOL+"\nOFF")
markup.row(itembtn21, itembtn22, itembtn23, itembtn24, itembtn25)
itembtn31 = types.KeyboardButton(CAMERA+"#1")
itembtn32 = types.KeyboardButton(CAMERA+"#2")
itembtn33 = types.KeyboardButton(DOOR+"\nSmall Door1")
itembtn34 = types.KeyboardButton(VERTICAL_TRAFFIC_LIGHT+"\nMORE")
markup.row(itembtn31, itembtn32, itembtn33, itembtn34)

strMessage = "Choose one action:"
try:
    bot.send_message(chat_id=cid, text=strMessage, reply_markup=markup)
except:
    pass

Can I do the same with your Chatbot?
screenshot_20170326-165747

@guidone
Copy link
Owner

guidone commented Mar 28, 2017

@gerardovf yes, I guess the node-red ui will eat all your special chars but you can prepare the payload in an upstream function node, something like

msg.payload = {
  message: 'The message with the buttons',
  buttons: [
    {
      value: 'text 1',
      label: 'label of the button 1',
      answer: 'this is the answer',
      alert: true,
      newLine: true
    },
    {
      value: 'text 2',
      label: 'another label',
      answer: 'this is the answer 2',
      alert: false
    }
  ]
}
return msg;

@gerardovf
Copy link
Author

@guidone You were right!! Now only the 'newLine' is still not working... (I wanted to show a 2x2 buttons keyboard)

I used this page to get the emoji conversion: http://www.fileformat.info/info/unicode/char/search.htm

Then in the upstream function node I inserted:

console.log(msg);
var chat = msg.chat();
var cloned = RED.util.cloneMessage(msg);
cloned.payload = {
type: "buttons",
content: 'The message with the buttons',
messageId: null,
chatId: chat.get('chatId'),
buttons: [
{
value: '\uD83D\uDD06\nON1',
label: 'label of the button 1',
answer: 'this is the answer',
alert: true,
newLine: false
},
{
value: '\u2B06\nON2',
label: 'another label',
answer: 'this is the answer 2',
alert: false,
newLine: true
},
{
value: '\uD83D\uDD05\nOFF1',
label: 'label of the button 3',
answer: 'this is the answer 3',
alert: true,
newLine: false
},
{
value: '\u2B07\nOFF2',
label: 'another label 2',
answer: 'this is the answer 4',
alert: false,
newLine: true
}
]
}
return cloned;

fancykbd

@gerardovf
Copy link
Author

@guidone I also checked that 'newLine' is working with "inline-buttons"

console.log(msg);
var chat = msg.chat();
var cloned = RED.util.cloneMessage(msg);
cloned.payload = {
type: "inline-buttons",
content: 'The message with the buttons',
messageId: null,
chatId: chat.get('chatId'),
buttons: [
{
value: '\uD83D\uDD06\nON1',
label: '\uD83D\uDD06\nON1',
answer: 'this is the answer',
newLine: false
},
{
value: '\u2B06\nON2',
label: '\u2B06\nON2',
answer: 'this is the answer 2',
newLine: true
},
{
value: '\uD83D\uDD05\nOFF1',
label: '\uD83D\uDD05\nOFF1',
answer: 'this is the answer 3',
newLine: false
},
{
value: '\u2B07\nOFF2',
label: '\u2B07\nOFF2',
answer: 'this is the answer 4',
newLine: true
}
]
}
return cloned;

fancybuttons

@guidone guidone closed this as completed Apr 3, 2017
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

2 participants