api.go
func NewWithWebhook(apiKey, webhookURL, certificate string) (*TelegramBotAPI, http.HandlerFunc, error) {
	toReturn := TelegramBotAPI{
		Updates:  make(chan BotUpdate),
		baseURIs: createEndpoints(fmt.Sprintf(apiBaseURI, apiKey)),
		closed:   make(chan struct{}),
		c:        newClient(fmt.Sprintf(apiBaseURI, apiKey)),
		updateC:  newClient(fmt.Sprintf(apiBaseURI, apiKey)),
	}
	user, err := toReturn.GetMe()
	if err != nil {
		return nil, nil, err
	}
	toReturn.ID = user.User.ID
	toReturn.Name = user.User.FirstName
	toReturn.Username = *user.User.Username

	file, err := os.Open(certificate)
	if err != nil {
		return nil, nil, err
	}

	err = toReturn.setWebhook(webhookURL, certificate, file)
	if err != nil {
		return nil, nil, err
	}

	updateFunc := func(w http.ResponseWriter, r *http.Request) {
		bytes, err := ioutil.ReadAll(r.Body)
		if err != nil {
			toReturn.Updates <- BotUpdate{err: err}
			return
		}

		update := &Update{}
		err = json.Unmarshal(bytes, update)
		if err != nil {
			toReturn.Updates <- BotUpdate{err: err}
			return
		}

		toReturn.Updates <- BotUpdate{update: *update}
	}

	return &toReturn, updateFunc, nil
}
func NewWithWebhook(apiKey, webhookURL, certificate string) (*TelegramBotAPI, http.HandlerFunc, error) {
	toReturn := TelegramBotAPI{
		Updates:  make(chan BotUpdate),
		baseURIs: createEndpoints(fmt.Sprintf(apiBaseURI, apiKey)),
		closed:   make(chan struct{}),
		c:        newClient(fmt.Sprintf(apiBaseURI, apiKey)),
		updateC:  newClient(fmt.Sprintf(apiBaseURI, apiKey)),
	}
	user, err := toReturn.GetMe()
	if err != nil {
		return nil, nil, err
	}
	toReturn.ID = user.User.ID
	toReturn.Name = user.User.FirstName
	toReturn.Username = *user.User.Username

	file, err := os.Open(certificate)
	if err != nil {
		return nil, nil, err
	}

	err = toReturn.setWebhook(webhookURL, certificate, file)
	if err != nil {
		return nil, nil, err
	}

	updateFunc := func(w http.ResponseWriter, r *http.Request) {
		bytes, err := ioutil.ReadAll(r.Body)
		if err != nil {
			toReturn.Updates <- BotUpdate{err: err}
			return
		}

		update := &Update{}
		err = json.Unmarshal(bytes, update)
		if err != nil {
			toReturn.Updates <- BotUpdate{err: err}
			return
		}

		toReturn.Updates <- BotUpdate{update: *update}
	}

	return &toReturn, updateFunc, nil
}
// NewWithWebhook creates a new API client for a Telegram bot using the apiKey
// provided. It will call the GetMe method to retrieve the bots id, name and
// username.
// In addition to the API client, a http.HandlerFunc will be returned. This
// handler func reacts to webhook requests and will put updates into the
// Updates channel.