K
K
korsamc2019-02-18 21:39:39
go
korsamc, 2019-02-18 21:39:39

How to properly pack json to pass the keyboard?

Here is my send message function, how to correctly pass "inline_keyboard"?

func Sendmessage(message string, chatID int,b *Bot){
response := fmt.Sprintf("%s%s/sendMessage",b.Base_url,b.Token)

var test = "{inline_keyboard:{\"text\":\"hello\",\"url\":\"ya.ru\"}"
answer := map[string]interface{}{"chat_id":chatID,"text":message,"reply_markup":test}

mapAnswer, _ := json.Marshal(answer)

networkRequest.ProxyPost(response,string(mapAnswer))
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pavlyuk, 2019-02-19
@korsamc

It's best to create a type for Inline keyboard and marshal from it

type InlineKeyboard [][]InlineKeyboardButton

type InlineKeyboardButton struct {
  Text         string
  Url          string
  CallbackData interface{}
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question