-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
136 additions
and
68 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 |
---|---|---|
@@ -1,18 +1,22 @@ | ||
[default] | ||
PROVIDER=slack | ||
SLACK_TOKEN= | ||
CHANNEL_ID= | ||
TOKEN=<bot-token> | ||
CHANNEL_ID=<channel-id> | ||
|
||
[slack] | ||
PROVIDER=slack | ||
SLACK_TOKEN= | ||
CHANNEL_ID= | ||
TOKEN=<bot-token> | ||
CHANNEL_ID=<channel-id> | ||
|
||
[google] | ||
PROVIDER=google | ||
WEB_HOOK_URL= | ||
WEB_HOOK_URL=<webhook-url> | ||
|
||
[telegram] | ||
PROVIDER=telegram | ||
TELEGRAM_BOT_TOKEN= | ||
TELEGRAM_CHAT_ID= | ||
TOKEN=<bot-token> | ||
CHAT_ID=<chat-id> | ||
|
||
[discord] | ||
PROVIDER=discord | ||
WEB_HOOK_URL=<webhook-url> |
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,8 @@ | ||
package constants | ||
|
||
const ( | ||
PROVIDER_SLACK="slack" | ||
PROVIDER_DISCORD="discord" | ||
PROVIDER_TELEGRAM="telegram" | ||
PROVIDER_GOOGLE="google" | ||
) |
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,49 @@ | ||
package providers | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/tech-thinker/chatz/config" | ||
) | ||
|
||
type discordProvider struct { | ||
config *config.Config | ||
} | ||
|
||
func (agent *discordProvider) Post(message string) (interface{}, error) { | ||
url := agent.config.WebHookURL | ||
|
||
payloadStr := fmt.Sprintf( | ||
`{"content": "%s"}`, | ||
message, | ||
) | ||
|
||
payload := strings.NewReader(payloadStr) | ||
|
||
req, _ := http.NewRequest("POST", url, payload) | ||
|
||
req.Header.Add("Content-Type", "application/json") | ||
req.Header.Add("User-Agent", "tech-thinker/chatz") | ||
|
||
res, err := http.DefaultClient.Do(req) | ||
if err!=nil { | ||
return nil, err | ||
} | ||
|
||
defer res.Body.Close() | ||
body, err := io.ReadAll(res.Body) | ||
return string(body), err | ||
} | ||
|
||
func (agent *discordProvider) Reply(threadId string, message string) (interface{}, error) { | ||
fmt.Println("Reply to discord not supported yet.") | ||
return nil, errors.New("Reply to discord not supported yet.") | ||
} | ||
|
||
func NewDiscordProvider(config *config.Config) Provider { | ||
return &discordProvider{config: config} | ||
} |
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
Oops, something went wrong.