func (hook *TelegramHook) verifyToken() error {
	endpoint := strings.Join([]string{hook.apiEndpoint, "getme"}, "/")
	res, err := hook.c.Get(endpoint)
	if err != nil {
		return err
	}
	defer res.Body.Close()

	apiRes := apiResponse{}
	err = json.NewDecoder(res.Body).Decode(&apiRes)
	if err != nil {
		return err
	}

	if !apiRes.Ok {
		// Received an error from the Telegram API
		msg := "Received error response from Telegram API"
		if apiRes.ErrorCode != nil {
			msg = fmt.Sprintf("%s (error code %d)", msg, *apiRes.ErrorCode)
		}
		if apiRes.Desc != nil {
			msg = fmt.Sprintf("%s: %s", msg, *apiRes.Desc)
		}
		j, _ := json.MarshalIndent(apiRes, "", "\t")
		msg = fmt.Sprintf("%s\n%s", msg, j)
		return fmt.Errorf(msg)
	}

	return nil
}
// verifyToken issues a test request to the Telegram API to ensure the
// provided token is correct and valid.
verifyToken issues a test request to the Telegram API to ensure the
provided token is correct and valid.
// verifyToken issues a test request to the Telegram API to ensure the // provided token is correct and valid .
func (hook *TelegramHook) verifyToken() error {
	endpoint := strings.Join([]string{hook.apiEndpoint, "getme"}, "/")
	res, err := hook.c.Get(endpoint)
	if err != nil {
		return err
	}
	defer res.Body.Close()
	apiRes := apiResponse{}
	err = json.NewDecoder(res.Body).Decode(&apiRes)
	if err != nil {
		return err
	}
	if !apiRes.Ok {
		msg := "Received error response from Telegram API"
		if apiRes.ErrorCode != nil {
			msg = fmt.Sprintf("%s (error code %d)", msg, *apiRes.ErrorCode)
		}
		if apiRes.Desc != nil {
			msg = fmt.Sprintf("%s: %s", msg, *apiRes.Desc)
		}
		j, _ := json.MarshalIndent(apiRes, "", "\t")
		msg = fmt.Sprintf("%s\n%s", msg, j)
		return fmt.Errorf(msg)
	}
	return nil
}
func ( hook * TelegramHook ) verifyToken ( ) error { endpoint := strings . Join ( [ ] string { hook . apiEndpoint , " " } , " " ) res , err := hook . c . Get ( endpoint ) if err != nil { return err } defer res . Body . Close ( ) apiRes := apiResponse { } err = json . NewDecoder ( res . Body ) . Decode ( & apiRes ) if err != nil { return err } if ! apiRes . Ok { msg := " " if apiRes . ErrorCode != nil { msg = fmt . Sprintf ( " " , msg , * apiRes . ErrorCode ) } if apiRes . Desc != nil { msg = fmt . Sprintf ( " " , msg , * apiRes . Desc ) } j , _ := json . MarshalIndent ( apiRes , " " , " \t " ) msg = fmt . Sprintf ( " \n " , msg , j ) return fmt . Errorf ( msg ) } return nil }
verifyToken issues a test request to the Telegram API to ensure the
provided token is correct and valid.
verifyToken issues a test request to the Telegram API to ensure the provided token is correct and valid .
// Received an error from the Telegram API