-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* upgrade to v7.2 * fix parse mod * all date fields now is int64 * feat: add date time getters * feat: bussines account router support * feat: return business in `Update.Msg()` * chore: ignore types_gen.go in coverage * chore: business bot sample and docs update * docs: add emoji to features
- Loading branch information
Showing
12 changed files
with
879 additions
and
125 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
ignore: | ||
- methods_gen.go | ||
- types_gen.go | ||
- examples |
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,79 @@ | ||
// Package contains simple echo bot, that demonstrates how to use handlers, filters and file uploads. | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"strings" | ||
|
||
"github.com/mr-linch/go-tg" | ||
"github.com/mr-linch/go-tg/examples" | ||
"github.com/mr-linch/go-tg/tgb" | ||
) | ||
|
||
var pm = tg.HTML | ||
|
||
func main() { | ||
examples.Run(tgb.NewRouter(). | ||
Message(func(ctx context.Context, mu *tgb.MessageUpdate) error { | ||
me, err := mu.Client.GetMe().Do(ctx) | ||
if err != nil { | ||
return fmt.Errorf("get me: %w", err) | ||
} | ||
|
||
if !me.CanConnectToBusiness { | ||
return mu.Answer("Bussines features is not enabled for current bot. Enable it via @BotFather").DoVoid(ctx) | ||
} | ||
|
||
if mu.From != nil && !mu.From.IsPremium { | ||
return mu.Answer("Bussines features works only for Telegram Premium users. Purchase subscription before use that bot.").DoVoid(ctx) | ||
} | ||
|
||
return mu.Answer("Connect bot in Telegram Bussines settings of your account").DoVoid(ctx) | ||
}, tgb.Command("start")). | ||
BusinessMessage(func(ctx context.Context, mu *tgb.MessageUpdate) error { | ||
if strings.Contains(mu.Text, "ping") { | ||
return mu.Answer("Pong!").BusinessConnectionID(mu.BusinessConnectionID).DoVoid(ctx) | ||
} | ||
|
||
log.Printf("New business message #%d: %s", mu.ID, mu.Text) | ||
|
||
return nil | ||
}). | ||
EditedBusinessMessage(func(ctx context.Context, mu *tgb.MessageUpdate) error { | ||
log.Printf("Edited business message: %#v", mu.Message) | ||
|
||
return nil | ||
}). | ||
BusinessConnection(func(ctx context.Context, bcu *tgb.BusinessConnectionUpdate) error { | ||
log.Printf("New business connection: %#v", bcu.BusinessConnection) | ||
|
||
lines := []string{} | ||
|
||
if bcu.IsEnabled { | ||
lines = append(lines, "🤝 Business connection estabilished") | ||
} else { | ||
lines = append(lines, "❌ Business connection closed") | ||
} | ||
|
||
lines = append(lines, "") | ||
|
||
lines = append(lines, pm.Line( | ||
pm.Bold("ID: "), pm.Code(bcu.BusinessConnection.ID), | ||
)) | ||
|
||
lines = append(lines, pm.Line( | ||
pm.Bold("Can Reply? "), pm.Code(fmt.Sprintf("%t", bcu.BusinessConnection.CanReply)), | ||
)) | ||
|
||
return bcu.Update.Reply(ctx, | ||
tg.NewSendMessageCall( | ||
bcu.User, | ||
pm.Text(lines...), | ||
). | ||
ParseMode(pm), | ||
) | ||
}), | ||
) | ||
} |
Oops, something went wrong.