wechat

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

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

Go to latest
Published: Mar 19, 2018 License: MIT Imports: 6 Imported by: 0

README

Go Report Card License GoDoc

WeChat Work

Use the WeChat work API in your Golang apps to send notifications

API reference for WeChat Work, please check this to know how to configure the settings below.

go get github.com/clem109/go-wechat-work

Usage

In the below example we include TextCard, Text and News however only the News will be sent as the MsgType is set to "news".

package main

import ("github.com/clem109/go-wechat-work")

func main() {
	wechat := WeChatWork{
		Config: Config{
			CorpID:     "corpid",
			CorpSecret: "somesecret",
			SkipVerify: true,
			Debug:      false,
			Notification: Notification{
				Agentid: 123456,
				MsgType: "news",
				ToUser:  "@all",
				ToParty: "@all",
				ToTag:   "@all",
				Safe:    0,
				TextCard: TextCard{
					Title:       "test",
					Description: "testing",
					MsgURL:      "someurl;",
					BtnTxt:      "p",
				},
				Text: Text{
					Content: "text message test",
				},
				News: News{
					Articles: []Article{
						Article{
							Title:       "Testing News",
							Description: "Star my repo ;)",
							URL:         "https://github.com/clem109/go-wechat-work",
							PicURL:      "https://raw.githubusercontent.com/clem109/glowing-gopher/master/gopher.jpeg",
						},
					},
				},
			},
		},
	}

	wechat.Exec()
}

Documentation

Overview

Please check the github Readme for an example of how to use this package. This package will help make sending notifications using WeChat Work 企业微信 easier. Make sure to refer to the api docs (chinese) to be able to know how to correctly configer each struct before sending the notification.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Article

type Article struct {
	Title       string `json:"title"`
	Description string `json:"description"`
	URL         string `json:"url"`
	PicURL      string `json:"picurl"`
	BtnTxt      string `json:"btntxt"`
}

Article defines an article to be sent

type Config

type Config struct {
	CorpID       string
	CorpSecret   string
	SkipVerify   bool
	Debug        bool
	Notification Notification
}

Config is the minimum information you need to send a notification, CorpId and CorpSecret are used to get the access token required before sending a notification.

type File

type File struct {
	MediaId string `json:"media_id"`
}

File sends a file that needs to be uploaded to wechat work

type Image

type Image struct {
	MediaId string `json:"media_id"`
}

Image is an image to send

type MpNews

type MpNews struct {
	MpNewsArticles []MpNewsArticle `json:"articles"`
}

Config is the minimum information you need to send a notification, CorpId and CorpSecret are used to get the access token required before sending a notification.

type MpNewsArticle

type MpNewsArticle struct {
	Title              string `json:"title"`
	Thumb_Media_ID     string `json:"thumb_media_id"`
	Author             string `json:"author"`
	Content_Source_Url string `json:"content_source_url"`
	Content            string `json:"content"`
	Digest             string `json:"digest"`
}

Config is the minimum information you need to send a notification, CorpId and CorpSecret are used to get the access token required before sending a notification.

type News

type News struct {
	Articles []Article `json:"articles"`
}

News is an array of articles to be sent

type Notification

type Notification struct {
	ToUser   string   `json:"touser"`
	ToParty  string   `json:"toparty"`
	ToTag    string   `json:"totag"`
	MsgType  string   `json:"msgtype"`
	Agentid  int      `json:"agentid"`
	TextCard TextCard `json:"textcard"`
	Text     Text     `json:"text"`
	Image    Image    `json:"image"`
	Voice    Voice    `json:"voice"`
	Video    Video    `json:"video"`
	File     File     `json:"file"`
	News     News     `json:"news"`
	MpNews   MpNews   `json:"mpnews"`
	Safe     int      `json:"safe"`
}

Notification defines information about who to send the notification to, the type of message and the agentid of your wechat work application. The other structs are to define which notification to send. If you define both a TextCard and a Text but set the message type to "text" then only a text will be sent.

type Response

type Response struct {
	Errcode     int    `json:"errcode"`
	Errmsg      string `json:"errmsg"`
	AccessToken string `json:"access_token"`
	ExpiresIn   int    `json:"expires_in"`
}

Config is the minimum information you need to send a notification, CorpId and CorpSecret are used to get the access token required before sending a notification.

type Text

type Text struct {
	Content string `json:"content"`
}

Text is a text message

type TextCard

type TextCard struct {
	Title       string `json:"title"`
	Description string `json:"description"`
	MsgURL      string `json:"url"`
	BtnTxt      string `json:"btntext"`
}

TextCard is a text card that will be sent as a notification.

type Video

type Video struct {
	MediaId     string `json:"media_id"`
	Title       string `json:"title"`
	Description string `json:"description"`
}

Video sends a video with a title and description

type Voice

type Voice struct {
	MediaId string `json:"media_id"`
}

Voice sends a voice message

type WeChatWork

type WeChatWork struct {
	Config   Config
	Response Response
}

Config is the minimum information you need to send a notification, CorpId and CorpSecret are used to get the access token required before sending a notification.

func (WeChatWork) Exec

func (p WeChatWork) Exec() error

Exec on a completed WeChatWork struct sends a message

Jump to

Keyboard shortcuts

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