Skip to content

Instantly share code, notes, and snippets.

@smartass08
Last active October 2, 2020 03:20
Show Gist options
  • Save smartass08/1d0c0b5e7c10ea24c42c669204b7ece6 to your computer and use it in GitHub Desktop.
Save smartass08/1d0c0b5e7c10ea24c42c669204b7ece6 to your computer and use it in GitHub Desktop.
import (
"github.com/PaulSonOfLars/gotg_md2html"
)
func MakeKeyboards(button []tg_md2html.Button) [][]ext.InlineKeyboardButton {
var allbuttons [][]ext.InlineKeyboardButton
for _, v := range button {
var button1 []ext.InlineKeyboardButton
tempbtn := ext.InlineKeyboardButton{
Text: v.Name,
Url: v.Content,
}
if !v.SameLine {
button1 = append(button1, tempbtn)
allbuttons = append(allbuttons, button1)
} else {
if allbuttons == nil {
button1 = append(button1, tempbtn)
allbuttons = append(allbuttons, button1)
} else {
button1 = append(allbuttons[len(allbuttons)-1], tempbtn)
allbuttons = allbuttons[:len(allbuttons)-1]
allbuttons = append(allbuttons, button1)
}
}
}
return allbuttons
}
func YourHandlerFunction(b ext.Bot, u *gotgbot.Update{
/*
your all things lies here
*/
html, btn := tg_md2html.MD2HTMLButtons("Some text you wanna parse from and generate buttons")
buttons := MakeKeyboards(btn)
msg := b.NewSendableMessage(u.EffectiveChat.Id, text)
msg.ReplyMarkup = &ext.InlineKeyboardMarkup{InlineKeyboard: &buttons}
msg.ParseMode = "HTML"
_, err := msg.Send()
if err == nil {
_, _ = b.ReplyMarkdownV2(u.EffectiveChat.Id, "Message sent successfully!", u.EffectiveMessage.MessageId)
} else {
_, _ = b.ReplyMarkdownV2(u.EffectiveChat.Id, fmt.Sprintf("Error sending message : %v", err.Error()), u.EffectiveMessage.MessageId)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment