~mendelmaleh/tg_colorbot

eeda1768b0c84398a92378d593e07940992bdf08 — Mendel E 11 months ago 9ec40be
Use html, add a web preview, and log api errors
1 files changed, 13 insertions(+), 4 deletions(-)

M main.go
M main.go => main.go +13 -4
@@ 2,6 2,7 @@ package main

import (
	"fmt"
	"html"
	"io/ioutil"
	"log"
	"strings"


@@ 78,19 79,27 @@ func main() {
				Description: fmt.Sprintf("Your color is %s", c.Color),
				ThumbURL:    fmt.Sprintf("https://dummy.mendel.sh/?width=64&color=%x&color=%x", c.Background, c.Name),
				InputMessageContent: tgbotapi.InputTextMessageContent{
					ParseMode: "markdown",
					Text: fmt.Sprintf("Your color is *%s*\n - name: `#%x`\n - background: `#%x`",
						c.Color, c.Name, c.Background),
					ParseMode: "html",
					Text: fmt.Sprintf(
						"Your color is <b>%s</b>\n - name: <code>#%x</code>\n - background: <code>#%x</code>\n<a href=\"%s\">&#8203;</a>",
						c.Color, c.Name, c.Background, html.EscapeString(fmt.Sprintf(
							"https://dummy.mendel.sh/web/%d/?width=64&color=%x&color=%x",
							q.From.ID, c.Background, c.Name,
						)),
					),
				},
			}

			results := make([]interface{}, 1)
			results[0] = r

			bot.AnswerInlineQuery(tgbotapi.InlineConfig{
			api, err := bot.AnswerInlineQuery(tgbotapi.InlineConfig{
				InlineQueryID: q.ID,
				Results:       results,
			})
			if err != nil {
				log.Println(api, err)
			}
		}
	}
}