英文:
How to display HTML markup from telegram telego Go bot?
问题
我想要像 Durger King 应用程序一样,通过我的机器人向客户推送格式化的消息。对于机器人的任何输入,都会显示一个显示为格式化的“让我们开始吧”的消息,并附带一张图片。在下面有一个“订购食物”WebApp按钮,点击后会打开 PWA。
这是一个简单的图片,还是格式化的 HTML?使用 telego Go 机器人如何发送图片或格式化的 HTML?
英文:
I'd like to push a formatted message to to clients from my bot in much the same way as the Durger King app does. In response to any input to the bot a message showing for formatted 'Let's get started' is displayed along with a picture. Underneath there is order food
WebApp button which opens the PWA.
Is this simply and image or is it formatted HTML, which would possibly be easier to manage.
How can one send either a an image or formatted HTML using the telego Go bot.
答案1
得分: 1
这是可能错误的实现方式:
var (
helloMsg = &tele.Message{Text: "<b>让我们开始吧!🎉</b>"}
)
func main() {
pref := tele.Settings{
Token: os.Getenv("TOKEN"),
Poller: &tele.LongPoller{Timeout: 5 * time.Second},
}
b, err := tele.NewBot(pref)
if err != nil {
log.Fatal(err)
return
}
b.Handle("/start", func(c tele.Context) error {
log.Println("检测到启动")
b.Send(c.Message().Sender, helloMsg.Text, &tele.SendOptions{
ParseMode: "HTML",
}, webapp)
return nil
})
}
我还没有尝试过是否可以使用上下文而不是机器人本身,并且返回nil
可能不是一个好主意。但基本上,这将把ParseMode设置为HTML,并且可以粘贴表情符号...
效果如下图所示:
英文:
Here's what is probably the wrong way of achieving this:
var (helloMsg = &tele.Message{Text: "<b>Let's get started!</b>🍟"})
func main() {
pref := tele.Settings{
Token: os.Getenv("TOKEN"),
Poller: &tele.LongPoller{Timeout: 5 * time.Second},
}
b, err := tele.NewBot(pref)
if err != nil {
log.Fatal(err)
return
}
b.Handle("/start", func(c tele.Context) error {
log.Println("Detected Start")
b.Send(c.Message().Sender, helloMsg.Text, &tele.SendOptions{
ParseMode: "HTML",
}, webapp)
return nil
})}
}
I haven't tried to see if it is possible to use the context instead of the bot itself, and returning nil
probably isn't a great idea. But essentially you this is setting the ParseMode to HTML and somehow the emoji can be pasted in...
This is what it looks like:
答案2
得分: 1
这是使用上下文的版本:
b.Handle("/start", func(c tele.Context) error {
log.Println("检测到开始")
b.Send(c.Message().Sender, helloMsg.Text, &tele.SendOptions{
ParseMode: "HTML",
}, webapp)
return nil
})
英文:
Here's the version using the context:
b.Handle("/start", func(c tele.Context) error {
log.Println("Detected Start")
b.Send(c.Message().Sender, helloMsg.Text, &tele.SendOptions{
ParseMode: "HTML",
}, webapp)
return nil
})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论