Skip to content

yageek/recast-go-bot-connector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoDoc Report Cart

recast-go-bot-connector

DEPRECATED: You should switch to the official Recast SDK Golang.

Package helping to deal with the Recast.AI Bot Connector

Installation

go get -u github.com/yageek/recast-go-bot-connector

Usage

Catch and reply

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

    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

    output := botconn.OutputMessage{
		Content: "Coucou",
		Kind:    botconn.TextKind,
	}
    err := conn.Broadcast(output)
    if err != nil {
		fmt.Println("Error:", err)
	} else {
		fmt.Println("Response succeeded")
	}