go-telegram-bot-api / telegram-bot-api

Golang bindings for the Telegram Bot API
https://go-telegram-bot-api.dev
MIT License
5.7k stars 879 forks source link

Sending message with method createChatInviteLink return nothing #541

Open mazanur opened 2 years ago

mazanur commented 2 years ago

Response from telegram {"invite_link":"https://t.me/+SEgfYrEGlSwzMjAy", "creator":{"id":1295847044,"is_bot":true,"first_name":"***","username":"*"},"member_limit":1,"creates_join_request":false,"is_primary":false,"is_revoked":false}

After Unmarshal, message has not inviteLink

temamagic commented 2 years ago

Hi! You must provide youre code first, if you want help

But it looks like that youre use it wrong way

You must use Request method and provide tgbotapi.CreateChatInviteLinkConfig for it

mazanur commented 2 years ago

Hi, that's exactly what I did.

image

But I want to use the Send method to create a link and return a Message, where the ChatInviteLink field will be

omerxx commented 1 year ago

Works for me like so:

        response, err := bot.Request(createInviteLinkConfig)
        if err != nil {
            return msg, err
        }
        var dat map[string]interface{}
        json.Unmarshal(response.Result, &dat)
MetaverseMan commented 4 months ago
   // just a simple demo that works
   import (
    "encoding/json"
    "fmt"
    "time"

    tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)
func gen_link(){
    var (
        chatCfg = tgbotapi.ChatConfig{ChatID: req.ChatID}
        resMap  map[string]interface{}
    )
    chatInviteLinkConfig := tgbotapi.CreateChatInviteLinkConfig{
        ChatConfig:        chatCfg,
        Name:                 "invite test",
        ExpireDate:         int(time.Now().Add(1 * time.Minute).Unix()),
        MemberLimit:        1,                                         
        CreatesJoinRequest: false,                                     
    }
    response, _ := bot.Request(chatInviteLinkConfig)
    err = json.Unmarshal(response.Result, &resMap)
    fmt.Println("resMap:", resMap)
        fmt.Println("invite_link:",resMap["invite_link"])
}