Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yageek/recast-go-bot-connector
A Recast Bot Connector API for Go
https://github.com/yageek/recast-go-bot-connector
chatbot go recast-ai
Last synced: about 2 months ago
JSON representation
A Recast Bot Connector API for Go
- Host: GitHub
- URL: https://github.com/yageek/recast-go-bot-connector
- Owner: yageek
- License: mit
- Created: 2017-03-28T16:07:41.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-04-05T10:27:39.000Z (almost 8 years ago)
- Last Synced: 2024-10-14T20:59:21.332Z (3 months ago)
- Topics: chatbot, go, recast-ai
- Language: Go
- Homepage:
- Size: 15.6 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![GoDoc](https://godoc.org/github.com/yageek/recast-go-bot-connector?status.png)](https://godoc.org/github.com/yageek/recast-go-bot-connector)
[![Report Cart](http://goreportcard.com/badge/yageek/recast-go-bot-connector)](http://goreportcard.com/report/yageek/recast-go-bot-connector)
# recast-go-bot-connector**DEPRECATED: You should switch to the official [Recast SDK Golang](https://github.com/RecastAI/SDK-Golang).**
Package helping to deal with the [Recast.AI Bot Connector](https://botconnector.recast.ai/)
## Installation
```
go get -u github.com/yageek/recast-go-bot-connector
```## Usage
### Catch and reply```go
package mainimport (
"fmt"
"github.com/bmizerany/pat"
"github.com/yageek/recast-go-bot-connector"
)
func main() {conf := botconn.ConnConfig{
Domain: botconn.RecastAPIDomain,
BotID: "BOT_ID",
UserSlug: "USER_SLUG",
UserToken: "USER_TOKEN",
}
conn := botconn.New(conf)
// Message routing
conn.UseHandler(botconn.MessageHandlerFunc(nextBus))// Router
mux := pat.New()
mux.Post("/chatbot", conn)http.HandleFunc("/", mux)
http.ListenAndServe(":8080", nil)
}func nextBus(w botconn.MessageWriter, m botconn.InputMessage) {
// Handle response
output := botconn.OutputMessage{
Content: "Coucou",
Kind: botconn.TextKind,
}
w.Reply(output)
}```
### Push a message to one participant```go
output := botconn.OutputMessage{
Content: "Coucou",
Kind: botconn.TextKind,
}
err := conn.Send(output, "CONVERSATION_ID", "SENDER_ID")
if err != nil {
fmt.Println("Error:", err)
} else {
fmt.Println("Response succeeded")
}
```### Broadcast a message to all participants
```go
output := botconn.OutputMessage{
Content: "Coucou",
Kind: botconn.TextKind,
}
err := conn.Broadcast(output)
if err != nil {
fmt.Println("Error:", err)
} else {
fmt.Println("Response succeeded")
}
```