Skip to content

Latest commit

 

History

History
70 lines (56 loc) · 1.81 KB

README.md

File metadata and controls

70 lines (56 loc) · 1.81 KB

SKYPE BOT

Example

See working example in example.go. Just set before the following env variables:

  • SKYPE_APP_ID // bot id
  • SKYPE_APP_SECRET // bot token
  • PORT // web server port (used for hook)

How to find bot app credentials?

Features

  • send text messages
  • receive text messages (setting of webhook is required)
  • receive conversation events (setting of webhook is required)

TODO

  • tests
  • refactoring
  • add command handler
  • send/receive attachments

Example

package main

import (
	"fmt"
	"log"
	"net/http"
	"os"
	"testing"

	"github.com/JILeXanDR/skypebot/bot"
	"github.com/JILeXanDR/skypebot/bot/message"
)

func main() {
	b := bot.New(bot.Config{
		AppID:     os.Getenv("SKYPE_APP_ID"),
		AppSecret: os.Getenv("SKYPE_APP_SECRET"),
		Logger:    log.New(os.Stdout, "", 0),
	})

	b.On(bot.EventMessage, func(activity *bot.Activity) {
		b.Send(activity, message.TextMessage(fmt.Sprintf(`Ваше сообщение "%s."`, activity.Text())))
	})

	b.On(bot.Command("ping"), func(activity *bot.Activity) {
		b.Send(activity, message.TextMessage("pong"))
	})

	b.On(bot.EventAddedToContacts, func(activity *bot.Activity) {
		b.Send(activity, message.TextMessage("привет! спасибо что добавил!"))
	})

	if err := b.Run(); err != nil {
		log.Fatal(err)
	}

	http.HandleFunc("/hook", b.WebHookHandler())

	log.Fatal(http.ListenAndServe(":"+os.Getenv("PORT"), nil))
}