dingbot

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2020 License: MIT Imports: 11 Imported by: 0

README

Dingbot

DingTalk robot golang library, and command line

Usage

As library

package main

import (
	"github.com/gladmo/dingbot"
)

func main() {
	token := "you ding talk access token"
	secret := "you ding talk secret, skip if old robot"

	text := "hello world"
	msg := dingbot.TextMessage(text)
	client := dingbot.New(token, secret)

	err := client.Send(msg)
	if err != nil {
		panic(err)
	}
}

Command line

preview
send dingtalk message

Usage:
  dingbot [command]

Available Commands:
  feedcard    send dingtalk feedcard message
  help        Help about any command
  init        init config
  link        send dingtalk link message
  markdown    send dingtalk markdown message
  text        send dingtalk text message
  version     Print the version number of Dingbot

Flags:
      --config string   config file (default is $HOME/dingbot.toml)
  -h, --help            help for dingbot
      --secret string   dingtalk robot secret
      --token string    dingtalk robot token (require)

Use "dingbot [command] --help" for more information about a command.
use Docker
$ docker pull gladmo/dingbot
$ docker run --rm gladmo/dingbot dingbot --help
Docker command alias
$ alias dingbot="docker run --rm gladmo/dingbot dingbot --token 'you token' --secret 'you secret'"
# then
$ dingbot text "hello world"
build
$ git clone https://github.com/gladmo/dingbot.git
$ cd dingbot
$ go mod vendor
$ go build -o dingbot cmd/main.go
$ ./dingbot version
send text message
$ ./dingbot --token "you token" --secret "you secret" text "hello world"
# or
$ echo "hello world" | ./dingbot --token "you token" --secret "you secret" text
send markdown message
$ ./dingbot markdown --title hello '## hello world'
# or
$ echo "hello world" | ./dingbot --token "you token" --secret "you secret" markdown --title hello
$ ./dingbot --token "you token" --secret "you secret" link --title hello --message-url 'https://6cm.co' 'hello world'
# or
$ echo "hello world" | ./dingbot --token "you token" --secret "you secret" link --title hello --message-url 'https://6cm.co'
send feed card message
$ ./dingbot --token "you token" --secret "you secret" feedcard --json-link '{"title":"时代的火车向前开","messageURL":"https://www.dingtalk.com/s?__biz=MzA4NjMwMTA2Ng==&mid=2650316842&idx=1&sn=60da3ea2b29f1dcc43a7c8e4a7c97a16&scene=2&srcid=09189AnRJEdIiWVaKltFzNTw&from=timeline&isappinstalled=0&key=&ascene=2&uin=&devicetype=android-23&version=26031933&nettype=WIFI","picURL":"https://gw.alicdn.com/tfs/TB1ayl9mpYqK1RjSZLeXXbXppXa-170-62.png"}' --json-link '{"title":"时代的火车向前开","messageURL":"https://www.dingtalk.com/s?__biz=MzA4NjMwMTA2Ng==&mid=2650316842&idx=1&sn=60da3ea2b29f1dcc43a7c8e4a7c97a16&scene=2&srcid=09189AnRJEdIiWVaKltFzNTw&from=timeline&isappinstalled=0&key=&ascene=2&uin=&devicetype=android-23&version=26031933&nettype=WIFI","picURL":"https://gw.alicdn.com/tfs/TB1ayl9mpYqK1RjSZLeXXbXppXa-170-62.png"}'
command alias
# replace path/to to you dingbot path
$ alias dingbot="path/to/dingbot --token 'you token' --secret 'you secret'"
# then
$ dingbot text "hello world"
use config
$ ./dingbot --token "you token" --secret "you secret" init dintbot.toml
$ ./dingbot --config dintbot.toml text "hello world"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DingTalk

type DingTalk struct {
	AccessToken string
	Secret      string
}

DingTalk client

func New added in v1.0.3

func New(accessToken, secret string) *DingTalk

New ding talk client

func (DingTalk) Send

func (th DingTalk) Send(msg Message) (err error)

Send 发送钉钉消息

type Links struct {
	Title      string `json:"title"`      // 必填
	MessageURL string `json:"messageURL"` // 必填
	PicURL     string `json:"picURL"`     // 必填
}

Links ...

func FeedCardLink(title, messageURL, picURL string) (l Links)

FeedCardLink create feedCard link

type Message

type Message struct {
	MsgType    string      `json:"msgtype"`
	Text       *text       `json:"text,omitempty"`
	Link       *link       `json:"link,omitempty"`
	Markdown   *markdown   `json:"markdown,omitempty"`
	ActionCard *actionCard `json:"actionCard,omitempty"`
	FeedCard   *feedCard   `json:"feedCard,omitempty"`
	AtMobiles  *at         `json:"at,omitempty"`
}

Message dingTalk all message type

func FeedCardMessage added in v1.0.2

func FeedCardMessage(links ...Links) (msg Message)

FeedCardMessage dingTalk feedCard message

func LinkMessage

func LinkMessage(title, text, messageURL, picURL string) (msg Message)

LinkMessage dingTalk link message

func MarkdownMessage

func MarkdownMessage(title, content string) (msg Message)

MarkdownMessage dingTalk markdown message

func TextMessage

func TextMessage(content string) (msg Message)

TextMessage dingTalk text message

func (*Message) At

func (th *Message) At(atAll bool, mobiles ...string) (err error)

At someone

func (Message) String

func (th Message) String() string

String message to string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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