1
0
telegram/export_chat_invite_link.go

32 lines
947 B
Go
Raw Normal View History

package telegram
import (
2017-09-04 20:54:28 +00:00
"errors"
"strconv"
json "github.com/pquerna/ffjson/ffjson"
http "github.com/valyala/fasthttp"
)
// ExportChatInviteLink export an invite link to a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns exported invite link as String on success.
func (bot *Bot) ExportChatInviteLink(chat interface{}) (string, error) {
var args http.Args
2017-09-04 20:54:28 +00:00
switch id := chat.(type) {
case int64: // Unique identifier for the target chat...
args.Add("chat_id", strconv.FormatInt(id, 10))
case string: // ...or username of the target supergroup or channel (in the format @username)
args.Add("chat_id", id)
default:
2017-09-04 20:54:28 +00:00
return "", errors.New(errorInt64OrString)
}
2017-09-05 09:20:10 +00:00
resp, err := bot.request(nil, "exportChatInviteLink", &args)
if err != nil {
2017-09-04 20:54:28 +00:00
return "", err
}
var data string
err = json.Unmarshal(*resp.Result, &data)
return data, err
}