🔀 Merge branch 'develop'
This commit is contained in:
commit
d4afafdf81
14
constants.go
14
constants.go
|
@ -25,6 +25,16 @@ const (
|
||||||
ChatSuperGroup = "supergroup"
|
ChatSuperGroup = "supergroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Command... represents global commands which should be supported by any bot.
|
||||||
|
// You can user IsCommandEqual method of Message for checking.
|
||||||
|
//
|
||||||
|
// See: https://core.telegram.org/bots#global-commands
|
||||||
|
const (
|
||||||
|
CommandStart = "start"
|
||||||
|
CommandHelp = "help"
|
||||||
|
CommandSettings = "settings"
|
||||||
|
)
|
||||||
|
|
||||||
// Entity... represents available and supported entity types
|
// Entity... represents available and supported entity types
|
||||||
const (
|
const (
|
||||||
EntityBold = "bold"
|
EntityBold = "bold"
|
||||||
|
@ -105,8 +115,8 @@ const (
|
||||||
|
|
||||||
// Mode... represents available and supported parsing modes of messages
|
// Mode... represents available and supported parsing modes of messages
|
||||||
const (
|
const (
|
||||||
ModeHTML = "html"
|
StyleHTML = "html"
|
||||||
ModeMarkdown = "markdown"
|
StyleMarkdown = "markdown"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Mime... represents available and supported MIME types of data
|
// Mime... represents available and supported MIME types of data
|
||||||
|
|
|
@ -1,24 +1,16 @@
|
||||||
# GoLang bindings for the Telegram API [![discord](https://discordapp.com/api/guilds/208605007744860163/widget.png)](https://discord.gg/dCWkgSS)
|
# GoLang bindings for the Telegram API
|
||||||
> This package is in active development and **not recommended for use in production for now**. Use [go dep](https://golang.github.io/dep/) to freeze the state of the package in your projects!
|
> This package is in active development and **not recommended for use in production for now**. Use [go dep](https://golang.github.io/dep/) to freeze the state of the package in your projects!
|
||||||
|
|
||||||
[![License](https://img.shields.io/npm/l/express.svg?maxAge=2592000)](LICENSE.md)
|
|
||||||
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Ftoby3d%2Ftelegram.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Ftoby3d%2Ftelegram?ref=badge_shield)
|
|
||||||
[![Build Status](https://travis-ci.org/toby3d/telegram.svg)](https://travis-ci.org/toby3d/telegram)
|
|
||||||
[![GoDoc](https://godoc.org/github.com/toby3d/telegram?status.svg)](https://godoc.org/github.com/toby3d/telegram)
|
|
||||||
[![Go Report](https://goreportcard.com/badge/github.com/toby3d/telegram)](https://goreportcard.com/report/github.com/toby3d/telegram)
|
|
||||||
[![Patreon](https://img.shields.io/badge/support-patreon-E6461A.svg?maxAge=2592000)](https://www.patreon.com/toby3d)
|
|
||||||
[![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/avelino/awesome-go)
|
|
||||||
|
|
||||||
## Start using telegram
|
## Start using telegram
|
||||||
Download and install it:
|
Download and install it:
|
||||||
`$ go get -u github.com/toby3d/telegram`
|
`$ go get -u gitlab.com/toby3d/telegram`
|
||||||
|
|
||||||
Import it in your code:
|
Import it in your code:
|
||||||
`import "github.com/toby3d/telegram"`
|
`import "gitlab.com/toby3d/telegram"`
|
||||||
|
|
||||||
## Need help?
|
## Need help?
|
||||||
- [Open new issue](https://github.com/toby3d/telegram/issues/new)
|
- [Open new issue](https://gitlab.com/toby3d/telegram/issues/new)
|
||||||
- [Discuss in Discord](https://discord.gg/dCWkgSS)
|
- [Discuss in Discord](https://discord.gg/dCWkgSS)
|
||||||
|
|
||||||
## License
|
## License
|
||||||
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Ftoby3d%2Ftelegram.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Ftoby3d%2Ftelegram?ref=badge_large)
|
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgitlab.com%2Ftoby3d%2Ftelegram.svg?type=large)](https://app.fossa.io/projects/git%2Bgitlab.com%2Ftoby3d%2Ftelegram?ref=badge_large)
|
|
@ -2,8 +2,8 @@
|
||||||
I develop this project in my spare time, and I do it and I will do it free of charge. However, you can make a donation or become a sponsor to make sure that I have enough coffee and pizza for night coding.
|
I develop this project in my spare time, and I do it and I will do it free of charge. However, you can make a donation or become a sponsor to make sure that I have enough coffee and pizza for night coding.
|
||||||
|
|
||||||
**These people sponsored current version of the project:**
|
**These people sponsored current version of the project:**
|
||||||
|
- Alina
|
||||||
- Aurielb
|
- Aurielb
|
||||||
- Daniil Tlenov
|
|
||||||
- @kirillDanshin
|
- @kirillDanshin
|
||||||
- MoD21k
|
- MoD21k
|
||||||
- @YamiOdymel
|
- Yami Odymel
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/toby3d/telegram"
|
"gitlab.com/toby3d/telegram"
|
||||||
)
|
)
|
||||||
|
|
||||||
const accessToken = "153667468:AAHlSHlMqSt1f_uFmVRJbm5gntu2HI4WW8I"
|
const accessToken = "153667468:AAHlSHlMqSt1f_uFmVRJbm5gntu2HI4WW8I"
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/toby3d/telegram"
|
"gitlab.com/toby3d/telegram"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -3,7 +3,7 @@ package test
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/toby3d/telegram"
|
"gitlab.com/toby3d/telegram"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetMe(t *testing.T) {
|
func TestGetMe(t *testing.T) {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/toby3d/telegram"
|
"gitlab.com/toby3d/telegram"
|
||||||
)
|
)
|
||||||
|
|
||||||
const replyToMessageID = 35
|
const replyToMessageID = 35
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/toby3d/telegram"
|
"gitlab.com/toby3d/telegram"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -3,12 +3,12 @@ package test
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/toby3d/telegram"
|
"gitlab.com/toby3d/telegram"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSetWebhook(t *testing.T) {
|
func TestSetWebhook(t *testing.T) {
|
||||||
ok, err := bot.SetWebhook(
|
ok, err := bot.SetWebhook(
|
||||||
telegram.NewWebhook("https://toby3d.github.io/telegram", nil),
|
telegram.NewWebhook("https://toby3d.ru/telegram", nil),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err.Error())
|
t.Error(err.Error())
|
||||||
|
|
49
utils.go
49
utils.go
|
@ -1,6 +1,7 @@
|
||||||
package telegram
|
package telegram
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
@ -23,3 +24,51 @@ func NewInlineMentionURL(userID int) *url.URL {
|
||||||
|
|
||||||
return link
|
return link
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewMarkdownBold(text string) string {
|
||||||
|
return fmt.Sprint("*", text, "*")
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMarkdownItalic(text string) string {
|
||||||
|
return fmt.Sprint("_", text, "_")
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMarkdownURL(text string, link *url.URL) string {
|
||||||
|
return fmt.Sprint("[", text, "](", link.String(), ")")
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMarkdownMention(text string, id int) string {
|
||||||
|
return fmt.Sprint("[", text, "](tg://user?id=", id, ")")
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMarkdownCode(text string) string {
|
||||||
|
return fmt.Sprint("`", text, "`")
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMarkdownCodeBlock(text string) string {
|
||||||
|
return fmt.Sprint("```", text, "```")
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewHtmlBold(text string) string {
|
||||||
|
return fmt.Sprint("<b>", text, "</b>")
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewHtmlItalic(text string) string {
|
||||||
|
return fmt.Sprint("<i>", text, "</i>")
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewHtmlURL(text string, link *url.URL) string {
|
||||||
|
return fmt.Sprint(`<a href="`, link.String(), `">`, text, `</a>`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewHtmlMention(text string, id int) string {
|
||||||
|
return fmt.Sprint(`<a href="tg://user?id=`, id, `">`, text, `</a>`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewHtmlCode(text string) string {
|
||||||
|
return fmt.Sprint("<code>", text, "</code>")
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewHtmlCodeBlock(text string) string {
|
||||||
|
return fmt.Sprint("<pre>", text, "</pre>")
|
||||||
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package telegram
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"log"
|
"log"
|
||||||
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/kirillDanshin/dlog"
|
"github.com/kirillDanshin/dlog"
|
||||||
|
@ -49,17 +50,17 @@ func (bot *Bot) NewLongPollingChannel(params *GetUpdatesParameters) UpdatesChann
|
||||||
|
|
||||||
// NewWebhookChannel creates channel for receive incoming updates via an outgoing
|
// NewWebhookChannel creates channel for receive incoming updates via an outgoing
|
||||||
// webhook.
|
// webhook.
|
||||||
func (bot *Bot) NewWebhookChannel(params *SetWebhookParameters, certFile, keyFile, set, listen, serve string) (updates UpdatesChannel) {
|
func (bot *Bot) NewWebhookChannel(setURL *url.URL, params *SetWebhookParameters, certFile, keyFile, serveAddr string) (updates UpdatesChannel) {
|
||||||
if params == nil {
|
if params == nil {
|
||||||
params = &SetWebhookParameters{
|
params = &SetWebhookParameters{
|
||||||
URL: set,
|
URL: setURL.String(),
|
||||||
MaxConnections: 40,
|
MaxConnections: 40,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
channel := make(chan Update, 100)
|
channel := make(chan Update, 100)
|
||||||
requiredPath := []byte(listen)
|
requiredPath := []byte(setURL.Path)
|
||||||
dlog.Ln("requiredPath:", string(requiredPath))
|
dlog.Ln("requiredPath:", string(requiredPath))
|
||||||
handleFunc := func(ctx *http.RequestCtx) {
|
handleFunc := func(ctx *http.RequestCtx) {
|
||||||
dlog.Ln("Request path:", string(ctx.Path()))
|
dlog.Ln("Request path:", string(ctx.Path()))
|
||||||
|
@ -80,10 +81,10 @@ func (bot *Bot) NewWebhookChannel(params *SetWebhookParameters, certFile, keyFil
|
||||||
go func() {
|
go func() {
|
||||||
if certFile != "" && keyFile != "" {
|
if certFile != "" && keyFile != "" {
|
||||||
dlog.Ln("Creating TLS router...")
|
dlog.Ln("Creating TLS router...")
|
||||||
err = http.ListenAndServeTLS(serve, certFile, keyFile, handleFunc)
|
err = http.ListenAndServeTLS(serveAddr, certFile, keyFile, handleFunc)
|
||||||
} else {
|
} else {
|
||||||
dlog.Ln("Creating simple router...")
|
dlog.Ln("Creating simple router...")
|
||||||
err = http.ListenAndServe(serve, handleFunc)
|
err = http.ListenAndServe(serveAddr, handleFunc)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err.Error())
|
log.Fatalln(err.Error())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user