You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

stv-git.sohatv.vn/tungtd/kingtalk-bot-api

Package Overview
Dependencies
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stv-git.sohatv.vn/tungtd/kingtalk-bot-api

Go Modules
Version
v1.0.1
Version published
Created
Source

Bindings bằng ngôn ngữ Go cho Bot API của KingTalk

Install

Đầu tiên, đảm bảo library đã được cài đặt và cập nhận phiên bản mới nhất:

go get -u stv-git.sohatv.vn/tungtd/kingtalk-bot-api.

Example

Ví dụ dưới đây là một bot đơn giản thực hiện lấy về các updates mới nhất rồi đăng chúng vào trong nhóm chat hiện tại:

package main

import (
	"log"
	ktbotapi "stv-git.sohatv.vn/tungtd/kingtalk-bot-api"
)

func main() {
	bot, err := ktbotapi.NewBotAPI("Token_Của_Bot")
	if err != nil {
		log.Panic(err)
	}

	bot.Debug = true

	log.Printf("Authorized on account %s", bot.Self.UserName)

	u := ktbotapi.NewUpdate(0)
	u.Timeout = 60

	updates, err := bot.GetUpdatesChan(u)

	for update := range updates {
		if update.Message == nil { // ignore any non-Message Updates
			continue
		}

		log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)

		msg := ktbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text)
		msg.ReplyToMessageID = update.Message.MessageID

		bot.Send(msg)
	}
}

Xem nhiều hơn các ví dụ tại wiki với nhiều thông tin chi tiết hơn vè cách sử dụng api, commands và các reply markup.

Dưới đây là một ví dụ cho bot muốn sử dụng webhook của Google App Engine.

package main

import (
	"log"
	"net/http"
	ktbotapi "stv-git.sohatv.vn/tungtd/kingtalk-bot-api"
)

func main() {
	bot, err := ktbotapi.NewBotAPI("Token_Của_Bot")
	if err != nil {
		log.Fatal(err)
	}

	bot.Debug = true

	log.Printf("Authorized on account %s", bot.Self.UserName)

	_, err = bot.SetWebhook(ktbotapi.NewWebhookWithCert("https://www.google.com:8443/"+bot.Token, "cert.pem"))
	if err != nil {
		log.Fatal(err)
	}
	info, err := bot.GetWebhookInfo()
	if err != nil {
		log.Fatal(err)
	}
	if info.LastErrorDate != 0 {
		log.Printf("KingTalk callback failed: %s", info.LastErrorMessage)
	}
	updates := bot.ListenForWebhook("/" + bot.Token)
	go http.ListenAndServeTLS("0.0.0.0:8443", "cert.pem", "key.pem", nil)

	for update := range updates {
		log.Printf("%+v\n", update)
	}
}

FAQs

Package last updated on 05 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts