chore: update message format

This commit is contained in:
Bo-Yi Wu 2020-06-20 13:51:48 +08:00
parent 3bccad3ca8
commit ce15798a06
3 changed files with 9 additions and 9 deletions

View File

@ -31,7 +31,7 @@ func main() {
Usage: "telegram user",
EnvVar: "PLUGIN_TO,TELEGRAM_TO,INPUT_TO",
},
cli.StringSliceFlag{
cli.StringFlag{
Name: "message",
Usage: "send telegram message",
EnvVar: "PLUGIN_MESSAGE,TELEGRAM_MESSAGE,INPUT_MESSAGE",
@ -302,7 +302,7 @@ func run(c *cli.Context) error {
MatchEmail: c.Bool("match.email"),
WebPreview: c.Bool("webpage.preview"),
To: c.StringSlice("to"),
Message: c.StringSlice("message"),
Message: c.String("message"),
MessageFile: c.String("message.file"),
TemplateVars: c.String("template.vars"),
Photo: c.StringSlice("photo"),

View File

@ -72,7 +72,7 @@ type (
MatchEmail bool
WebPreview bool
To []string
Message []string
Message string
MessageFile string
TemplateVars string
Photo []string
@ -270,7 +270,7 @@ func (p Plugin) Exec() (err error) {
return fmt.Errorf("error loading message file '%s': %v", p.Config.MessageFile, err)
}
case len(p.Config.Message) > 0:
message = p.Config.Message
message = []string{p.Config.Message}
default:
p.Config.Format = formatMarkdown
message = p.Message()

View File

@ -97,7 +97,7 @@ func TestSendMessage(t *testing.T) {
Config: Config{
Token: os.Getenv("TELEGRAM_TOKEN"),
To: []string{os.Getenv("TELEGRAM_TO"), os.Getenv("TELEGRAM_TO") + ":appleboy@gmail.com", "中文ID", "1234567890"},
Message: []string{"Test Telegram Chat Bot From Travis or Local", "commit message: 『{{ build.message }}』", " "},
Message: "Test Telegram Chat Bot From Travis or Local, commit message: 『{{ build.message }}』",
Photo: []string{"tests/github.png", "1234", " "},
Document: []string{"tests/gophercolor.png", "1234", " "},
Sticker: []string{"tests/github-logo.png", "tests/github.png", "1234", " "},
@ -114,12 +114,12 @@ func TestSendMessage(t *testing.T) {
assert.NotNil(t, err)
plugin.Config.Format = formatMarkdown
plugin.Config.Message = []string{"Test escape under_score"}
plugin.Config.Message = "Test escape under_score"
err = plugin.Exec()
assert.NotNil(t, err)
// disable message
plugin.Config.Message = []string{}
plugin.Config.Message = ""
err = plugin.Exec()
assert.NotNil(t, err)
}
@ -145,7 +145,7 @@ func TestBotError(t *testing.T) {
Config: Config{
Token: "appleboy",
To: []string{os.Getenv("TELEGRAM_TO"), "中文ID", "1234567890"},
Message: []string{"Test Telegram Chat Bot From Travis or Local", " "},
Message: "Test Telegram Chat Bot From Travis or Local",
},
}
@ -410,7 +410,7 @@ func TestProxySendMessage(t *testing.T) {
Config: Config{
Token: os.Getenv("TELEGRAM_TOKEN"),
To: []string{os.Getenv("TELEGRAM_TO")},
Message: []string{"Send message from socks5 proxy URL."},
Message: "Send message from socks5 proxy URL.",
Debug: false,
Socks5: os.Getenv("SOCKS5"),
},