Skip to content

Commit

Permalink
✨ feat: added timestamp message pattern while sending to telegram bot #…
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Jan 15, 2024
1 parent bc42839 commit 6cea845
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
8 changes: 8 additions & 0 deletions blueprint/blueprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ import (
"html/template"
"log"
"net/url"
"time"

"github.com/sivaosorg/govm/builder"
"github.com/sivaosorg/govm/timex"
"github.com/sivaosorg/govm/utils"
)

func NewCard() *card {
c := &card{}
c.SetTimestamp(time.Now())
return c
}

func (c *card) SetTimestamp(value time.Time) *card {
c.Timestamp = value.Format(timex.TimeFormat20060102150405)
return c
}

Expand Down
2 changes: 2 additions & 0 deletions blueprint/blueprint_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var TypeIcons = map[IconText]string{
// CardDefault is the HTML template for the card
var CardDefault = `
<b> {{.Icon}} {{.Title}} </b>
<b> 📌 {{.Timestamp}} </b>
<i>{{.Description}}</i>
{{if .ImageUrl}}
<img src="{{.ImageUrl}}">
Expand All @@ -37,6 +38,7 @@ var CardDefault = `
// CardMarkdownDefault is the Markdown template for the card
var CardMarkdownDefault = `
**{{.Icon}} {{.Title}}**
**📌 {{.Timestamp}}**
*{{.Description}}*
{{if .ImageUrl}}
![Image]({{.ImageUrl}})
Expand Down
1 change: 1 addition & 0 deletions blueprint/blueprint_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package blueprint
type IconText string

type card struct {
Timestamp string `json:"timestamp"`
Icon string `json:"icon"`
IconText IconText `json:"icon_text,omitempty"`
Title string `json:"title,omitempty"`
Expand Down
26 changes: 26 additions & 0 deletions example/govm_test.go
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
package example

import (
"testing"

"github.com/sivaosorg/govm/bot/telegram"
)

// bot: t.me/javis_notify_forum_bot
// group: https://t.me/javis_forum_bot
// chat_id: -1002042977093
// token: 6806983892:AAGcPZiuNktLFnyVWrRyOyYssECcVmNJSRo
func createTelegramService() telegram.TelegramService {
options := telegram.NewTelegramOptionConfig().SetType(telegram.ModeHTML)
svc := telegram.NewTelegramService(*telegram.GetTelegramConfigSample().
SetChatId([]int64{-1002042977093}).
SetToken("6806983892:AAGcPZiuNktLFnyVWrRyOyYssECcVmNJSRo").
SetDebugMode(false),
*options)

return svc
}

func TestCardNotification(t *testing.T) {
svc := createTelegramService()
svc.SendWarning("Kafka Stream", "Kafka Streams is a part of the Apache Kafka project that enables developers to build real-time processing applications, where data can be ingested, processed, and transformed in real-time as it flows through the Kafka cluster. Kafka Streams is a library for building scalable and fault-tolerant stream processing applications without the need for a separate processing cluster.")
}

0 comments on commit 6cea845

Please sign in to comment.