func (hook *TelegramHook) sendMessage(msg string) error {
	apiReq := apiRequest{
		ChatID:    hook.targetID,
		Text:      msg,
		ParseMode: "HTML",
	}
	b, err := json.Marshal(apiReq)
	if err != nil {
		return err
	}

	res, err := hook.c.Post(
		strings.Join([]string{hook.apiEndpoint, "sendmessage"}, "/"),
		"application/json",
		bytes.NewReader(b),
	)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Encountered error when issuing request to Telegram API, %v", err)
		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)
		}
		return fmt.Errorf(msg)
	}

	return nil
}
// sendMessage issues the provided message to the Telegram API.
sendMessage issues the provided message to the Telegram API.
// sendMessage issues the provided message to the Telegram API .
func (hook *TelegramHook) sendMessage(msg string) error {
	apiReq := apiRequest{
		ChatID:    hook.targetID,
		Text:      msg,
		ParseMode: "HTML",
	}
	b, err := json.Marshal(apiReq)
	if err != nil {
		return err
	}
	res, err := hook.c.Post(
		strings.Join([]string{hook.apiEndpoint, "sendmessage"}, "/"),
		"application/json",
		bytes.NewReader(b),
	)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Encountered error when issuing request to Telegram API, %v", err)
		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)
		}
		return fmt.Errorf(msg)
	}
	return nil
}
func ( hook * TelegramHook ) sendMessage ( msg string ) error { apiReq := apiRequest { ChatID : hook . targetID , Text : msg , ParseMode : " " , } b , err := json . Marshal ( apiReq ) if err != nil { return err } res , err := hook . c . Post ( strings . Join ( [ ] string { hook . apiEndpoint , " " } , " " ) , " " , bytes . NewReader ( b ) , ) if err != nil { fmt . Fprintf ( os . Stderr , " " , err ) 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 ) } return fmt . Errorf ( msg ) } return nil }
sendMessage issues the provided message to the Telegram API.
sendMessage issues the provided message to the Telegram API .
// Received an error from the Telegram API