forked from projectdiscovery/notify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Discord threads (projectdiscovery#191)
* Fix a spelling mistake in README.md change example `notify -version` to `notify -verbose`. It's a small typo. * add yaml parameters to discord config * fix Username and avatarURL passing to shoutrrr service * add SendThreaded function with corresponding types which sends messages to specific chat threads. Implement optional threads setting for discord provider. * small refactor * removing extra new line --------- Co-authored-by: 程越 <44216455+cyicz123@users.noreply.github.com> Co-authored-by: Sandeep Singh <sandeep@projectdiscovery.io> Co-authored-by: mzack <marco.rivoli.nvh@gmail.com>
- Loading branch information
1 parent
ab77820
commit e0dcf6f
Showing
6 changed files
with
93 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ on: | |
pull_request: | ||
workflow_dispatch: | ||
|
||
|
||
jobs: | ||
build: | ||
name: Test Builds | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package discord | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/projectdiscovery/notify/pkg/utils/httpreq" | ||
) | ||
|
||
func (options *Options) SendThreaded(message string) error { | ||
|
||
payload := APIRequest{ | ||
Content: message, | ||
Username: options.DiscordWebHookUsername, | ||
AvatarURL: options.DiscordWebHookAvatarURL, | ||
} | ||
|
||
encoded, err := json.Marshal(payload) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
body := bytes.NewReader(encoded) | ||
|
||
webHookURL := fmt.Sprintf("%s?thread_id=%s", options.DiscordWebHookURL, options.DiscordThreadID) | ||
|
||
req, err := http.NewRequest(http.MethodPost, webHookURL, body) | ||
req.Header.Set("Content-Type", "application/json") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = httpreq.NewClient().Do(req) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package discord | ||
|
||
type APIRequest struct { | ||
Content string `json:"content,omitempty"` | ||
AvatarURL string `json:"avatar_url,omitempty"` | ||
Username string `json:"username,omitempty"` | ||
} |