diff --git a/main.go b/main.go index c6674a9..58b5592 100644 --- a/main.go +++ b/main.go @@ -109,10 +109,10 @@ func main() { Usage: "send message when only match email", EnvVar: "PLUGIN_ONLY_MATCH_EMAIL,INPUT_ONLY_MATCH_EMAIL", }, - cli.BoolTFlag{ - Name: "webpage.preview", - Usage: "toggle web-page preview", - EnvVar: "PLUGIN_WEBPAGE_PREVIEW,INPUT_WEBPAGE_PREVIEW", + cli.BoolFlag{ + Name: "disable.webpage.preview", + Usage: "disables link previews for links in this message", + EnvVar: "PLUGIN_WEBPAGE_PREVIEW,INPUT_DISABLE_WEB_PAGE_PREVIEW", }, cli.StringFlag{ Name: "format", @@ -304,7 +304,6 @@ func run(c *cli.Context) error { Token: c.String("token"), Debug: c.Bool("debug"), MatchEmail: c.Bool("match.email"), - WebPreview: c.Bool("webpage.preview"), To: c.StringSlice("to"), Message: c.String("message"), MessageFile: c.String("message.file"), @@ -321,6 +320,8 @@ func run(c *cli.Context) error { Format: c.String("format"), GitHub: c.Bool("github"), Socks5: c.String("socks5"), + + DisableWebPagePreview: c.Bool("disable.webpage.preview"), }, } diff --git a/plugin.go b/plugin.go index 95a46aa..0f6f5c4 100644 --- a/plugin.go +++ b/plugin.go @@ -70,7 +70,6 @@ type ( Token string Debug bool MatchEmail bool - WebPreview bool To []string Message string MessageFile string @@ -87,6 +86,8 @@ type ( Format string GitHub bool Socks5 string + + DisableWebPagePreview bool } // Plugin values. @@ -363,7 +364,7 @@ func (p Plugin) Exec() (err error) { msg := tgbotapi.NewMessage(user, txt) msg.ParseMode = p.Config.Format - msg.DisableWebPagePreview = !p.Config.WebPreview + msg.DisableWebPagePreview = !p.Config.DisableWebPagePreview if err := p.Send(bot, msg); err != nil { return err } diff --git a/plugin_test.go b/plugin_test.go index 290d2d7..faa3ab5 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -124,6 +124,30 @@ func TestSendMessage(t *testing.T) { assert.NotNil(t, err) } +func TestDisableWebPagePreviewMessage(t *testing.T) { + plugin := Plugin{ + Config: Config{ + Token: os.Getenv("TELEGRAM_TOKEN"), + To: []string{os.Getenv("TELEGRAM_TO")}, + DisableWebPagePreview: true, + Debug: false, + }, + } + + err := plugin.Exec() + assert.NotNil(t, err) + + plugin.Config.Format = formatMarkdown + plugin.Config.Message = "DisableWebPagePreview https://www.google.com.tw" + err = plugin.Exec() + assert.NotNil(t, err) + + // disable message + plugin.Config.DisableWebPagePreview = false + err = plugin.Exec() + assert.NotNil(t, err) +} + func TestBotError(t *testing.T) { plugin := Plugin{ Repo: Repo{