talk: Let the token be in a file

This commit is contained in:
Hamcha 2017-05-09 13:37:23 +02:00
parent 318a3f8d16
commit 43ca576345
1 changed files with 8 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"strconv"
@ -54,6 +55,13 @@ type QResponse struct {
const talkBaseURL = "https://api.api.ai/v1"
func inittalk() {
if strings.HasPrefix(*talktoken, "@") {
data, err := ioutil.ReadFile((*talktoken)[1:])
if err != nil {
panic(err)
}
*talktoken = string(data)
}
if *talktoken == "" {
panic(fmt.Errorf("API token for api.ai must be provided! (provide it or --disable talk)"))
}