Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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 main

import (
"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")
}
```