aichaos / rivescript-go

A RiveScript interpreter for Go. RiveScript is a scripting language for chatterbots.
https://www.rivescript.com/
MIT License
60 stars 16 forks source link

Cannot sort replies while using in http Handler #13

Closed itsbalamurali closed 7 years ago

itsbalamurali commented 7 years ago

Hi,

I am trying to build a telegram bot and using Echo web framework. trying to integrate this library but unable to do so.

here is my sample function code which is called during webhook call

func NewMsg(message *models.Message) (string, error) {

    botbrain := brain.New(brain.UTF8())
    botbrain.SetHandler("javascript", brain.NewJSHandler(botbrain))
    err := botbrain.LoadDirectory("../rivescripts/")
    if err != nil {
        log.Printf("Error loading directory: %s", err)
        os.Exit(1)
    }
    botbrain.SortReplies()
    reply := botbrain.Reply(strconv.Itoa(int(message.User.ID)), message.Text)
    return reply, nil
}

but it gives ERR: Replies Not Sorted

Can you please help?

kirsle commented 7 years ago

Verify that the reply path for LoadDirectory actually existed (turning on debug mode and seeing as it parses the source files is a good way to determine this).

Also, it's not very efficient to initialize the bot and get its reply on every individual request. For larger bot brains it can take many seconds to scan and parse the source files over and over again. See "Make a Single Shared Bot Instance" on the RiveScript Wiki.

itsbalamurali commented 7 years ago

Well, thought documentation my bad didn't go through it and it worked. Thank you 💯 👍