1
0
telegram/get_chat_member.go

34 lines
905 B
Go
Raw Normal View History

2017-09-04 19:47:27 +00:00
package telegram
import (
"errors"
"strconv"
json "github.com/pquerna/ffjson/ffjson"
http "github.com/valyala/fasthttp"
)
// GetChatMember get information about a member of a chat. Returns a ChatMember object on success.
func (bot *Bot) GetChatMember(chat interface{}, user int) (*ChatMember, error) {
var args http.Args
args.Add("user_id", strconv.Itoa(user)) // Unique identifier of the target user
2017-09-04 20:54:28 +00:00
switch id := chat.(type) {
2017-09-04 19:47:27 +00:00
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 @channelusername)
args.Add("chat_id", id)
default:
return nil, errors.New(errorInt64OrString)
}
2017-09-05 08:02:20 +00:00
resp, err := bot.request("getChatMember", &args)
2017-09-04 19:47:27 +00:00
if err != nil {
return nil, err
}
var data ChatMember
err = json.Unmarshal(*resp.Result, &data)
return &data, err
}