1
0

🔀 Merge branch 'develop'

This commit is contained in:
Maxim Lebedev 2018-06-20 18:41:07 +05:00
commit d4afafdf81
No known key found for this signature in database
GPG Key ID: F8978F46FF0FFA4F
11 changed files with 81 additions and 29 deletions

View File

@ -25,6 +25,16 @@ const (
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
const (
EntityBold = "bold"
@ -105,8 +115,8 @@ const (
// Mode... represents available and supported parsing modes of messages
const (
ModeHTML = "html"
ModeMarkdown = "markdown"
StyleHTML = "html"
StyleMarkdown = "markdown"
)
// Mime... represents available and supported MIME types of data

View File

@ -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!
[![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
Download and install it:
`$ go get -u github.com/toby3d/telegram`
`$ go get -u gitlab.com/toby3d/telegram`
Import it in your code:
`import "github.com/toby3d/telegram"`
`import "gitlab.com/toby3d/telegram"`
## 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)
## 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)

View File

@ -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.
**These people sponsored current version of the project:**
- Alina
- Aurielb
- Daniil Tlenov
- @kirillDanshin
- MoD21k
- @YamiOdymel
- Yami Odymel

View File

@ -4,7 +4,7 @@ import (
"os"
"testing"
"github.com/toby3d/telegram"
"gitlab.com/toby3d/telegram"
)
const accessToken = "153667468:AAHlSHlMqSt1f_uFmVRJbm5gntu2HI4WW8I"

View File

@ -5,7 +5,7 @@ import (
"testing"
"time"
"github.com/toby3d/telegram"
"gitlab.com/toby3d/telegram"
)
const (

View File

@ -3,7 +3,7 @@ package test
import (
"testing"
"github.com/toby3d/telegram"
"gitlab.com/toby3d/telegram"
)
func TestGetMe(t *testing.T) {

View File

@ -5,7 +5,7 @@ import (
"testing"
"time"
"github.com/toby3d/telegram"
"gitlab.com/toby3d/telegram"
)
const replyToMessageID = 35

View File

@ -4,7 +4,7 @@ import (
"net/url"
"testing"
"github.com/toby3d/telegram"
"gitlab.com/toby3d/telegram"
)
const (

View File

@ -3,12 +3,12 @@ package test
import (
"testing"
"github.com/toby3d/telegram"
"gitlab.com/toby3d/telegram"
)
func TestSetWebhook(t *testing.T) {
ok, err := bot.SetWebhook(
telegram.NewWebhook("https://toby3d.github.io/telegram", nil),
telegram.NewWebhook("https://toby3d.ru/telegram", nil),
)
if err != nil {
t.Error(err.Error())

View File

@ -1,6 +1,7 @@
package telegram
import (
"fmt"
"net/url"
"strconv"
)
@ -23,3 +24,51 @@ func NewInlineMentionURL(userID int) *url.URL {
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>")
}

View File

@ -3,6 +3,7 @@ package telegram
import (
"bytes"
"log"
"net/url"
"time"
"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
// 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 {
params = &SetWebhookParameters{
URL: set,
URL: setURL.String(),
MaxConnections: 40,
}
}
var err error
channel := make(chan Update, 100)
requiredPath := []byte(listen)
requiredPath := []byte(setURL.Path)
dlog.Ln("requiredPath:", string(requiredPath))
handleFunc := func(ctx *http.RequestCtx) {
dlog.Ln("Request path:", string(ctx.Path()))
@ -80,10 +81,10 @@ func (bot *Bot) NewWebhookChannel(params *SetWebhookParameters, certFile, keyFil
go func() {
if certFile != "" && keyFile != "" {
dlog.Ln("Creating TLS router...")
err = http.ListenAndServeTLS(serve, certFile, keyFile, handleFunc)
err = http.ListenAndServeTLS(serveAddr, certFile, keyFile, handleFunc)
} else {
dlog.Ln("Creating simple router...")
err = http.ListenAndServe(serve, handleFunc)
err = http.ListenAndServe(serveAddr, handleFunc)
}
if err != nil {
log.Fatalln(err.Error())