BeaverBot

package module
v0.0.0-...-a665d0f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2023 License: AGPL-3.0 Imports: 17 Imported by: 0

README

功能陆续迁移到 CoralBot

BeaverBot

概述

钉钉机器人开发库

快速开始

要求
  • go 1.18以上
安装
$ go get -u github.com/BoyChai/BeaverBot
使用

使用之前需要配置钉钉机器人的消息推送地址并且需指定服务器出口IP事件主机为本程序主机和端口,之后,创建一个名为example.go

$ touch example.go

接下来,将以下代码放入example.go

package main

import (
	"github.com/BoyChai/BeaverBot"
)

func main() {
	h, _ := BeaverBot.NewHandle("你的appKey", "你的AppSecret")
	var e BeaverBot.Event
	c := []BeaverBot.Condition{{
		Key:   &e.Text.Content,
		Value: "hello",
		Regex: true,
	}}
	BeaverBot.NewTask(BeaverBot.Task{
		Condition: c,
		Run: func() {
			msg := BeaverBot.NewTextMsg("hello")
			h.SendGroupMessages(h.AppKey, msg, e.ConversationId)
		},
	})

	BeaverBot.RunBeaverBot(":8080", &e)
}


您可以通过以下方式运行代码go run example.go,运行之后可以在群聊里面@机器人发送hello即可收到回复。效果如下: 效果

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllHandle []*Handle
View Source
var Tasks []Task

Functions

func NewActionCard2Msg

func NewActionCard2Msg(text string, title string, actionTitle1 string, actionURL1 string, actionTitle2 string, actionURL2 string) string

func NewActionCard3Msg

func NewActionCard3Msg(text string, title string, actionTitle1 string, actionURL1 string, actionTitle2 string, actionURL2 string, actionTitle3 string, actionURL3 string) string

func NewActionCard4Msg

func NewActionCard4Msg(text string, title string, actionTitle1 string, actionURL1 string, actionTitle2 string, actionURL2 string, actionTitle3 string, actionURL3 string, actionTitle4 string, actionURL4 string) string

func NewActionCard5Msg

func NewActionCard5Msg(text string, title string, actionTitle1 string, actionURL1 string, actionTitle2 string, actionURL2 string, actionTitle3 string, actionURL3 string, actionTitle4 string, actionURL4 string, actionTitle5 string, actionURL5 string) string

func NewActionCard6Msg

func NewActionCard6Msg(text string, title string, buttonTitle1 string, buttonUrl1 string, buttonTitle2 string, buttonUrl2 string) string

func NewActionCardMsg

func NewActionCardMsg(text string, title string, singleTitle string, singleURL string) string

func NewImageMsg

func NewImageMsg(photoURL string) string

func NewLinkMsg

func NewLinkMsg(text string, title string, picUrl string, msgUrl string) string

func NewMarkdownMsg

func NewMarkdownMsg(title string, text string) string

func NewTask

func NewTask(task Task)

NewTask 创建一个动作

func NewTextMsg

func NewTextMsg(content string) string

func RunBeaverBot

func RunBeaverBot(port string, e *Event)

Types

type Condition

type Condition struct {
	Key   interface{}
	Value string
	Regex bool
}

Condition 触发条件

type Event

type Event struct {
	HandleID       int
	ConversationId string `json:"conversationId"`
	AtUsers        []struct {
		DingtalkId string `json:"dingtalkId"`
		StaffId    string `json:"staffId"`
	} `json:"atUsers"`
	ChatbotCorpId             string `json:"chatbotCorpId"`
	ChatbotUserId             string `json:"chatbotUserId"`
	MsgId                     string `json:"msgId"`
	SenderNick                string `json:"senderNick"`
	IsAdmin                   bool   `json:"isAdmin"`
	SenderStaffId             string `json:"senderStaffId"`
	SessionWebhookExpiredTime int64  `json:"sessionWebhookExpiredTime"`
	CreateAt                  int64  `json:"createAt"`
	SenderCorpId              string `json:"senderCorpId"`
	ConversationType          string `json:"conversationType"`
	SenderId                  string `json:"senderId"`
	ConversationTitle         string `json:"conversationTitle"`
	IsInAtList                bool   `json:"isInAtList"`
	SessionWebhook            string `json:"sessionWebhook"`
	Text                      struct {
		Content string `json:"content"`
	} `json:"text"`
	Msgtype string `json:"msgtype"`
	// contains filtered or unexported fields
}

Event 整个事件信息

type Handle

type Handle struct {
	AppKey    string
	AppSecret string
	// contains filtered or unexported fields
}

func NewHandle

func NewHandle(appKey string, appSecret string) (*Handle, error)

NewHandle 创建动作执行器

func (*Handle) DeleteGroupMessages

func (h *Handle) DeleteGroupMessages(robotCode string, processQueryKeys []string, conversationId string) (statusCode int, bodyData string, err error)

DeleteGroupMessages 批量撤回群聊消息

func (*Handle) DeletePrivateMessages

func (h *Handle) DeletePrivateMessages(robotCode string, processQueryKeys []string) (statusCode int, bodyData string, err error)

DeletePrivateMessages 批量撤回单聊消息

func (*Handle) GetID

func (h *Handle) GetID() int

GetID 获取当前命令执行器的id

func (*Handle) QueryGroupMessages

func (h *Handle) QueryGroupMessages(robotCode string, conversationId string, processQueryKey string, maxResults string, nextToken string) (statusCode int, bodyData string, err error)

QueryGroupMessages 查询企业机器人群聊消息用户已读状态

func (*Handle) QueryPrivateMessages

func (h *Handle) QueryPrivateMessages(robotCode string, processQueryKeys string) (statusCode int, bodyData string, err error)

QueryPrivateMessages 批量查询机器人单单聊消息是否已读

func (*Handle) SendGroupMessages

func (h *Handle) SendGroupMessages(robotCode string, msg string, conversationId string) (statusCode int, bodyData string, err error)

SendGroupMessages 企业机器人向内部群发消息

func (*Handle) SendPrivateMessages

func (h *Handle) SendPrivateMessages(robotCode string, msg string, userId []string) (statusCode int, bodyData string, err error)

SendPrivateMessages 批量发送单聊消息

type Task

type Task struct {
	Condition []Condition
	Run       func()
}

Task 创建一个任务

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL