-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (57 loc) · 1.78 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"context"
"encoding/json"
"fmt"
"log"
"os"
"github.com/joho/godotenv"
"github.com/krognol/go-wolfram"
"github.com/shomali11/slacker"
"github.com/tidwall/gjson"
witai "github.com/wit-ai/wit-go/v2"
)
var wolframClient *wolfram.Client
func printCommandEvents(analyticsChannel <-chan *slacker.CommandEvent) {
for event := range analyticsChannel {
fmt.Println("Command Events")
fmt.Println(event.Timestamp)
fmt.Println(event.Command)
fmt.Println(event.Parameters)
fmt.Println(event.Event)
fmt.Println()
}
}
func main() {
godotenv.Load(".env")
bot := slacker.NewClient(os.Getenv("oauth_bottokens"), os.Getenv("socket_token"))
wolframClient := &wolfram.Client{AppID: os.Getenv("wolfram_id")}
client := witai.NewClient(os.Getenv("wit.ai_token"))
go printCommandEvents(bot.CommandEvents())
bot.Command("i have a doubt - <message>", &slacker.CommandDefinition{
Description: "Send any question :",
Examples: []string{"who is the chief minister of tamilnadu"},
Handler: func(botCtx slacker.BotContext, request slacker.Request, response slacker.ResponseWriter) {
query := request.Param("message")
msg, _ := client.Parse(&witai.MessageRequest{
Query: query,
})
data, _ := json.MarshalIndent(msg, "", " ")
softcopy := string(data[:])
val := gjson.Get(softcopy, "entities.wit$wolfram_search_query:wolfram_search_query.0.value")
ans := val.String()
res, err := wolframClient.GetSpokentAnswerQuery(ans, wolfram.Metric, 1000)
if err != nil {
fmt.Println("Here Is An Error")
}
fmt.Println(val)
response.Reply(res)
},
})
strt, cancel := context.WithCancel(context.Background())
defer cancel()
err := bot.Listen(strt)
if err != nil {
log.Fatal(err)
}
}