Exemple #1
0
func handleURLAction(a models.Action, b models.Bot) (string, error) {

	resp, err := http.Get(a.Content)
	defer resp.Body.Close()

	if err != nil {
		return "", err
	}

	content, _ := ioutil.ReadAll(resp.Body)
	pathString := *a.DataPath

	str := utility.ParseJSON(content, pathString)
	for i := 0; i < 3; i++ {
		if !utility.ValidateURL(str, a.IsImageType()) {
			fmt.Printf("Invalid URL: %v\n", str)
			str = utility.ParseJSON(content, pathString)
		} else {
			return str, nil
		}
	}

	return "", errors.New("Failed to handle URL action")
}