2017-09-04 20:23:42 +00:00
package telegram
import (
2017-09-04 20:54:28 +00:00
"errors"
"strconv"
2017-09-04 20:23:42 +00:00
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 ) {
2017-09-04 20:23:42 +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 @username)
args . Add ( "chat_id" , id )
default :
2017-09-04 20:54:28 +00:00
return "" , errors . New ( errorInt64OrString )
2017-09-04 20:23:42 +00:00
}
2017-09-05 09:20:10 +00:00
resp , err := bot . request ( nil , "exportChatInviteLink" , & args )
2017-09-04 20:23:42 +00:00
if err != nil {
2017-09-04 20:54:28 +00:00
return "" , err
2017-09-04 20:23:42 +00:00
}
var data string
err = json . Unmarshal ( * resp . Result , & data )
return data , err
}