Skip to content

Commit 7f7cbed

Browse files
Merge pull request #6 from N7WEra/main
Add support for Google Chat
2 parents efb0059 + a91d6c8 commit 7f7cbed

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import (
2+
"bytes"
3+
"encoding/json"
4+
"fmt"
5+
"net/http"
6+
"strings"
7+
"github.com/MythicMeta/MythicContainer/webhookstructs"
8+
)
9+
type GoogleChatMessage struct {
10+
Text string `json:"text,omitempty"`
11+
}
12+
func sendGoogleChatMessage(webhookURL string, msg webhookstructs.SlackWebhookMessage) error {
13+
var builder strings.Builder
14+
for _, att := range msg.Attachments {
15+
if att.Title != "" {
16+
builder.WriteString(fmt.Sprintf("*%s*\n", att.Title))
17+
}
18+
if att.Blocks != nil {
19+
for _, block := range *att.Blocks {
20+
if block.Text != nil && block.Text.Text != "" {
21+
builder.WriteString(fmt.Sprintf("%s\n", block.Text.Text))
22+
}
23+
if block.Fields != nil {
24+
for _, f := range *block.Fields {
25+
if f.Text != "" {
26+
builder.WriteString(fmt.Sprintf("%s\n", f.Text))
27+
}
28+
}
29+
}
30+
}
31+
}
32+
builder.WriteString("\n")
33+
}
34+
payload := GoogleChatMessage{
35+
Text: builder.String(),
36+
}
37+
jsonData, err := json.Marshal(payload)
38+
if err != nil {
39+
return err
40+
}
41+
resp, err := http.Post(webhookURL, "application/json", bytes.NewBuffer(jsonData))
42+
if err != nil {
43+
return err
44+
}
45+
defer resp.Body.Close()
46+
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
47+
return fmt.Errorf("google chat webhook returned status %s", resp.Status)
48+
}
49+
return nil
50+
}

C2_Profiles/basic_webhook/my_webhooks/sendingUtils.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ func sendMessage(webhookURL string, newMessage webhookstructs.SlackWebhookMessag
1717
if strings.Contains(webhookURL, "discord.com") {
1818
return sendDiscordMessage(webhookURL, newMessage)
1919
}
20+
21+
// Detect Google Chat basic_webhook URL
22+
if strings.Contains(webhookURL, "chat.googleapis.com") {
23+
return sendGoogleChatMessage(webhookURL, newMessage)
24+
}
2025

2126
// Detect Slack basic_webhook URL
2227
if strings.Contains(webhookURL, "slack.com") {
@@ -25,5 +30,5 @@ func sendMessage(webhookURL string, newMessage webhookstructs.SlackWebhookMessag
2530
}
2631

2732
// Unsupported basic_webhook type
28-
return errors.New("unsupported basic_webhook type: currently only Slack and Discord are supported")
33+
return errors.New("unsupported basic_webhook type: currently only Slack, Discord and Google Chat are supported")
2934
}

0 commit comments

Comments
 (0)