-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat] Add telegram push and config file
- Loading branch information
1 parent
8a5dd55
commit 100e94e
Showing
7 changed files
with
98 additions
and
13 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
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,57 @@ | ||
package push | ||
|
||
import ( | ||
"MedalHelper/util" | ||
"testing" | ||
) | ||
|
||
func TestPushDeerPush(t *testing.T) { | ||
push := PushDeerPush{ | ||
util.Endpoint{ | ||
Name: "push", | ||
Type: "push_deer", | ||
URL: "http://api2.pushdeer.com/message/push", | ||
Token: "<YOUR-TOKEN-HERE>", | ||
}, | ||
} | ||
if err := push.Submit(Data{ | ||
Title: "# Just for test", | ||
Content: "Good Morning!", | ||
}); err != nil { | ||
t.Fatalf("Push error: %v", err) | ||
} | ||
} | ||
|
||
func TestPushPlusPush(t *testing.T) { | ||
push := PushDeerPush{ | ||
util.Endpoint{ | ||
Name: "push", | ||
Type: "push_plus", | ||
URL: "http://www.pushplus.plus/send", | ||
Token: "<YOUR-TOKEN-HERE>", | ||
}, | ||
} | ||
if err := push.Submit(Data{ | ||
Title: "# Just for test", | ||
Content: "Good Morning!", | ||
}); err != nil { | ||
t.Fatalf("Push error: %v", err) | ||
} | ||
} | ||
|
||
func TestTelegramPush(t *testing.T) { | ||
push := TelegramPush{ | ||
util.Endpoint{ | ||
Name: "push", | ||
Type: "telegram", | ||
URL: "https://api.telegram.org/bot<YOUR-BOT-TOKEN-HERE>/sendMessage", | ||
Token: "<YOUR-TELEGRAM-CHATID>", | ||
}, | ||
} | ||
if err := push.Submit(Data{ | ||
Title: "# Just for test", | ||
Content: "Good Morning!", | ||
}); err != nil { | ||
t.Fatalf("Push error: %v", err) | ||
} | ||
} |
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,27 @@ | ||
package push | ||
|
||
import ( | ||
"MedalHelper/manager" | ||
"MedalHelper/util" | ||
"fmt" | ||
"net/url" | ||
) | ||
|
||
const TelegramName string = "telegram" | ||
|
||
// Telegram BOT push | ||
type TelegramPush struct { | ||
util.Endpoint | ||
} | ||
|
||
// Submit data to endpoint and finish one task | ||
func (push TelegramPush) Submit(pd Data) error { | ||
// Prepare content and header | ||
data := url.Values{ | ||
"chat_id": []string{push.Token}, | ||
"text": []string{fmt.Sprintf("%s, %s", pd.Title, pd.Content)}, | ||
} | ||
// Submit info | ||
_, err := manager.Get(push.URL, data) | ||
return err | ||
} |
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