Self-handshaking test (still failing)

This commit is contained in:
Ilya Kowalewski 2015-06-27 14:30:35 +03:00
parent dd4efff2f3
commit dbcd156645
2 changed files with 61 additions and 22 deletions

View File

@ -1,4 +1,39 @@
# Telebot # Telebot
>Telegram bot framework written in Go >Telebot is a convenient wrapper to Telegram Bots API, written in Golang.
TBA. Bots are special Telegram accounts designed to handle messages automatically. Users can interact with bots by sending them command messages in private or group chats. These accounts serve as an interface for code running somewhere on your server.
Telebot offers a convenient wrapper to Bots API, so you shouldn't even care about networking at all.
```go
import (
"time"
"github.com/tucnak/telebot"
)
func main() {
bot, err := telebot.Create("SECRET TOKEN")
if err != nil {
return
}
messages := make(chan telebot.Message)
bot.Listen(messages, 1*time.Second)
for message := range messages {
if message.Text == "/hi" {
bot.SendMessage(message.Chat,
"Hello, "+message.Sender.FirstName+"!")
}
}
}
```
## Features
- Listening to messages from users / group chats
- Replying to users, depending on scope
## TODO
- Message forwarding
- Sophiesticated content types (Document, Contact, Video, etc)
- Reply keyboard styles

View File

@ -1,39 +1,43 @@
package telebot package telebot
import ( import (
"log" "fmt"
"os"
"testing" "testing"
"time" "time"
) )
const TESTING_TOKEN = "107177593:AAHBJfF3nv3pZXVjXpoowVhv_KSGw56s8zo" func TestTelebot(t *testing.T) {
token := os.Getenv("TELEBOT_SECRET")
func TestCreate(t *testing.T) { if token == "" {
_, err := Create(TESTING_TOKEN) fmt.Println("ERROR: " +
if err != nil { "In order to test telebot functionality, you need to set up " +
t.Fatal(err) "TELEBOT_SECRET environmental variable, which represents an API " +
} "key to a Telegram bot.\n")
} t.Fatal("Could't find TELEBOT_SECRET, aborting.")
func TestListen(t *testing.T) {
if testing.Short() {
t.Skip("Skipping test in short mode.")
} }
bot, err := Create(TESTING_TOKEN) bot, err := Create(token)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
messages := make(chan Message) messages := make(chan Message)
intelligence := "welcome to the jungle"
bot.SendMessage(bot.Identity, intelligence)
bot.Listen(messages, 1*time.Second) bot.Listen(messages, 1*time.Second)
log.Println("Listening...") select {
case message := <-messages:
for message := range messages { {
if message.Text == "/hi" { if message.Text != intelligence {
bot.SendMessage(message.Chat, t.Error("Self-handshake failed.")
"Hello, "+message.Sender.FirstName+"!") }
} }
case <-time.After(5 * time.Second):
t.Error("Self-handshake test took too long, aborting.")
} }
} }