Changkun's Blog欧长坤的博客

Science and art, life in between.科学与艺术,生活在其间。

  • Home首页
  • Ideas想法
  • Posts文章
  • Tags标签
  • Bio关于
Changkun Ou

Changkun Ou

Human-AI interaction researcher, engineer, and writer.人机交互研究者、工程师、写作者。

Bridging HCI, AI, and systems programming. Building intelligent human-in-the-loop optimization systems. Informed by psychology, philosophy, and social science.连接人机交互、AI 与系统编程。构建智能的人在环优化系统。融合心理学、哲学与社会科学。

Science and art, life in between.科学与艺术,生活在其间。

276 Blogs博客
165 Tags标签
Changkun's Blog欧长坤的博客

Telegram BotTelegram 机器人

Published at发布于:: 2020-12-12

Because the COVID situation in Europe is still terrible, even shopping at an Apple Store requires an appointment in advance. Since I urgently needed to visit an Apple Store recently but couldn’t find any available appointment slots, I quickly hacked together a tool to check availability and send a reminder message via Telegram when an appointment becomes available. Tool link: https://changkun.de/s/apreserve

Interacting with Telegram using Go is straightforward:

  1. Create a bot from BotFather
  2. Obtain the bot’s token and the chat ID for your conversation with it
  3. Then you can handle messages
  • BotFather: https://t.me/botfather
  • Tg bot API Go bindings: https://github.com/go-telegram-bot-api/telegram-bot-api
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
package main

import (
	tg "github.com/go-telegram-bot-api/telegram-bot-api"
)

func main() {
	token := …
	chatid := …
	bot, err := tg.NewBotAPI(token)
	if err != nil { … }
	bot.Send(tg.NewMessage(chatid, "text"))
}

因为欧洲疫情依然很糟糕,所以现在甚至于想去苹果店购物都要提前预约。因为最近急需要去苹果店一次,又苦于刷不到可用的预约位置,刚刚顺手就糊一个工具来检查,当预约可用时给telegram发送一条提醒消息。工具地址: https://changkun.de/s/apreserve

用 Go 和 telegram 进行交互没有任何难度:

  1. 从 botfather 创建一个 bot
  2. 获得这个 bot 的 token 以及跟它对话的 chatid
  3. 于是可以处理消息了
  • BotFather: https://t.me/botfather
  • Tg bot API Go bindings: https://github.com/go-telegram-bot-api/telegram-bot-api
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
package main

import (
	tg "github.com/go-telegram-bot-api/telegram-bot-api"
)

func main() {
	token := …
	chatid := …
	bot, err := tg.NewBotAPI(token)
	if err != nil { … }
	bot.Send(tg.NewMessage(chatid, "text"))
}
© 2008 - 2026 Changkun Ou. All rights reserved.保留所有权利。 | PV/UV: /
0%