Update README.md.

bot-api-6.1
Syfaro 2017-12-29 01:26:54 -06:00
parent ef374648bf
commit 8b7b15afc2
3 changed files with 24 additions and 26 deletions

View File

@ -16,9 +16,6 @@ without any additional features. There are other projects for creating
something with plugins and command handlers without having to design
all that yourself.
Use `github.com/go-telegram-bot-api/telegram-bot-api` for the latest
version, or use `gopkg.in/telegram-bot-api.v4` for the stable build.
Join [the development group](https://telegram.me/go_telegram_bot_api) if
you want to ask questions or discuss development.
@ -32,7 +29,8 @@ package main
import (
"log"
"gopkg.in/telegram-bot-api.v4"
"github.com/go-telegram-bot-api/telegram-bot-api"
)
func main() {
@ -72,9 +70,10 @@ you may use a slightly different method.
package main
import (
"gopkg.in/telegram-bot-api.v4"
"log"
"net/http"
"github.com/go-telegram-bot-api/telegram-bot-api"
)
func main() {
@ -87,7 +86,7 @@ func main() {
log.Printf("Authorized on account %s", bot.Self.UserName)
_, err = bot.SetWebhook(tgbotapi.NewWebhookWithCert("https://www.google.com:8443/"+bot.Token, "cert.pem"))
_, err = bot.Request(tgbotapi.NewWebhookWithCert("https://www.google.com:8443/"+bot.Token, "cert.pem"))
if err != nil {
log.Fatal(err)
}
@ -108,5 +107,5 @@ properly signed.
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 3560 -subj "//O=Org\CN=Test" -nodes
Now that [Let's Encrypt](https://letsencrypt.org) has entered public beta,
you may wish to generate your free TLS certificate there.
Now that [Let's Encrypt](https://letsencrypt.org) is available, you may
wish to generate your free TLS certificate there.

32
bot.go
View File

@ -243,23 +243,7 @@ func (bot *BotAPI) IsMessageToMe(message Message) bool {
return strings.Contains(message.Text, "@"+bot.Self.UserName)
}
// Send will send a Chattable item to Telegram.
//
// It requires the Chattable to send.
func (bot *BotAPI) Send(c Chattable) (Message, error) {
resp, err := bot.Request(c)
if err != nil {
return Message{}, err
}
var message Message
err = json.Unmarshal(resp.Result, &message)
return message, err
}
// Request makes a request to Telegram that returns an APIResponse, rather than
// a Message.
// Request sends a Chattable to Telegram, and returns the APIResponse.
func (bot *BotAPI) Request(c Chattable) (APIResponse, error) {
switch t := c.(type) {
case Fileable:
@ -288,6 +272,20 @@ func (bot *BotAPI) Request(c Chattable) (APIResponse, error) {
}
}
// Send will send a Chattable item to Telegram and provides the
// returned Message.
func (bot *BotAPI) Send(c Chattable) (Message, error) {
resp, err := bot.Request(c)
if err != nil {
return Message{}, err
}
var message Message
err = json.Unmarshal(resp.Result, &message)
return message, err
}
// debugLog checks if the bot is currently running in debug mode, and if
// so will display information about the request and response in the
// debug log.

View File

@ -1,8 +1,9 @@
package tgbotapi_test
import (
"github.com/go-telegram-bot-api/telegram-bot-api"
"testing"
"github.com/go-telegram-bot-api/telegram-bot-api"
)
func TestNewInlineQueryResultArticle(t *testing.T) {