Self-handshaking test (still failing)

pull/3/head
Ilya Kowalewski 9 years ago
parent dd4efff2f3
commit dbcd156645

@ -1,4 +1,39 @@
# 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

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

Loading…
Cancel
Save