Documentation
¶
Index ¶
- Constants
- type AcceptCommunityInviteResult
- type ActionButton
- type ActionButtonType
- type AddChatMemberParams
- type AddChatMemberResult
- type AddCommunityGroupParams
- type AddCommunityMemberParams
- type AutomationStatus
- type BanChatMemberParams
- type BanChatMemberResult
- type BanCommunityMemberParams
- type Bot
- func (b *Bot) Connected() bool
- func (b *Bot) GetStatus(ctx context.Context) (*BotPauseStatus, error)
- func (b *Bot) HandleWebhook(body []byte)
- func (b *Bot) OnCallbackQuery(h func(*CallbackQuery))
- func (b *Bot) OnConnected(h func())
- func (b *Bot) OnDisconnected(h func(code int, reason string))
- func (b *Bot) OnError(h func(error))
- func (b *Bot) OnMessage(h func(*Message))
- func (b *Bot) Pause(ctx context.Context) (*BotPauseStatus, error)
- func (b *Bot) PauseInChat(ctx context.Context, chatID int64) (*ChatAutomationResult, error)
- func (b *Bot) Reply(ctx context.Context, event any, text string, opts ...SendMessageParams) (*SendResult, error)
- func (b *Bot) Resume(ctx context.Context) (*BotPauseStatus, error)
- func (b *Bot) ResumeInChat(ctx context.Context, chatID int64) (*ChatAutomationResult, error)
- func (b *Bot) Start()
- func (b *Bot) Stop()
- type BotGroupEntry
- type BotOption
- type BotPauseStatus
- type BotProfile
- type BotProfileResource
- type CallbackQuery
- type CarouselCard
- type Chat
- type ChatAutomationResult
- type ChatInviteLink
- type ChatMemberInfo
- type ChatType
- type ChatsResource
- func (r *ChatsResource) AddMember(ctx context.Context, params AddChatMemberParams) (*AddChatMemberResult, error)
- func (r *ChatsResource) BanMember(ctx context.Context, params BanChatMemberParams) (*BanChatMemberResult, error)
- func (r *ChatsResource) CreateInviteLink(ctx context.Context, params CreateChatInviteLinkParams) (*ChatInviteLink, error)
- func (r *ChatsResource) CreateSingleUseInviteLink(ctx context.Context, params CreateChatInviteLinkParams) (*ChatInviteLink, error)
- func (r *ChatsResource) GetAdministrators(ctx context.Context, params GetChatAdministratorsParams) (*GetChatAdministratorsResult, error)
- func (r *ChatsResource) GetInviteLinks(ctx context.Context, params GetChatInviteLinksParams) (*GetChatInviteLinksResult, error)
- func (r *ChatsResource) GetMember(ctx context.Context, params GetChatMemberParams) (*ChatMemberInfo, error)
- func (r *ChatsResource) GetMyGroups(ctx context.Context) (*GetMyGroupsResult, error)
- func (r *ChatsResource) Iterate(ctx context.Context, pageSize int, fn func(*Chat) bool) error
- func (r *ChatsResource) LeaveChat(ctx context.Context, params LeaveChatParams) (*LeaveChatResult, error)
- func (r *ChatsResource) List(ctx context.Context, params GetChatsParams) (ChatsResult, error)
- func (r *ChatsResource) PromoteMember(ctx context.Context, params PromoteChatMemberParams) (*PromoteChatMemberResult, error)
- func (r *ChatsResource) RevokeInviteLink(ctx context.Context, params RevokeChatInviteLinkParams) (*RevokeChatInviteLinkResult, error)
- type ChatsResult
- type CommunitiesResource
- func (r *CommunitiesResource) AcceptInvite(ctx context.Context, params CommunityInviteCodeParams) (*AcceptCommunityInviteResult, error)
- func (r *CommunitiesResource) AddGroup(ctx context.Context, params AddCommunityGroupParams) (*CommunityActionResult, error)
- func (r *CommunitiesResource) AddMember(ctx context.Context, params AddCommunityMemberParams) (*CommunityActionResult, error)
- func (r *CommunitiesResource) ApproveGroupRequest(ctx context.Context, params CommunityRequestActionParams) (*CommunityActionResult, error)
- func (r *CommunitiesResource) ApproveJoinRequest(ctx context.Context, params CommunityRequestActionParams) (*CommunityActionResult, error)
- func (r *CommunitiesResource) BanMember(ctx context.Context, params BanCommunityMemberParams) (*CommunityActionResult, error)
- func (r *CommunitiesResource) Create(ctx context.Context, params CreateCommunityParams) (*Community, error)
- func (r *CommunitiesResource) CreateInviteLink(ctx context.Context, params CreateCommunityInviteLinkParams) (*CommunityInvite, error)
- func (r *CommunitiesResource) Delete(ctx context.Context, params GetCommunityParams) (*CommunityActionResult, error)
- func (r *CommunitiesResource) Get(ctx context.Context, params GetCommunityParams) (*CommunityDetail, error)
- func (r *CommunitiesResource) GetGroupRequests(ctx context.Context, params GetCommunityParams) ([]CommunityGroupRequest, error)
- func (r *CommunitiesResource) GetInviteLinks(ctx context.Context, params GetCommunityParams) (*GetCommunityInviteLinksResult, error)
- func (r *CommunitiesResource) GetJoinRequests(ctx context.Context, params GetCommunityParams) ([]CommunityJoinRequest, error)
- func (r *CommunitiesResource) Join(ctx context.Context, params GetCommunityParams) (*CommunityActionResult, error)
- func (r *CommunitiesResource) Leave(ctx context.Context, params GetCommunityParams) (*CommunityActionResult, error)
- func (r *CommunitiesResource) List(ctx context.Context) (GetMyCommunitiesResult, error)
- func (r *CommunitiesResource) ListAdmin(ctx context.Context) ([]Community, error)
- func (r *CommunitiesResource) PreviewInvite(ctx context.Context, params CommunityInviteCodeParams) (*CommunityInvitePreview, error)
- func (r *CommunitiesResource) PromoteMember(ctx context.Context, params PromoteCommunityMemberParams) (*CommunityActionResult, error)
- func (r *CommunitiesResource) RejectGroupRequest(ctx context.Context, params CommunityRequestActionParams) (*CommunityActionResult, error)
- func (r *CommunitiesResource) RejectJoinRequest(ctx context.Context, params CommunityRequestActionParams) (*CommunityActionResult, error)
- func (r *CommunitiesResource) RemoveGroup(ctx context.Context, params RemoveCommunityGroupParams) (*CommunityActionResult, error)
- func (r *CommunitiesResource) RevokeInviteLink(ctx context.Context, params RevokeCommunityInviteLinkParams) (*CommunityActionResult, error)
- func (r *CommunitiesResource) Update(ctx context.Context, params UpdateCommunityParams) (*Community, error)
- type Community
- type CommunityActionResult
- type CommunityDetail
- type CommunityGroup
- type CommunityGroupRequest
- type CommunityInvite
- type CommunityInviteCodeParams
- type CommunityInvitePreview
- type CommunityJoinRequest
- type CommunityMember
- type CommunityRequestActionParams
- type CreateChatInviteLinkParams
- type CreateCommunityInviteLinkParams
- type CreateCommunityParams
- type CreateStoryParams
- type DeleteMessageParams
- type DeleteResult
- type EditMessageParams
- type EditMessageResult
- type ErrorCode
- type FileInput
- type GetChatAdministratorsParams
- type GetChatAdministratorsResult
- type GetChatInviteLinksParams
- type GetChatInviteLinksResult
- type GetChatMemberParams
- type GetChatsParams
- type GetCommunityInviteLinksResult
- type GetCommunityParams
- type GetMyCommunitiesResult
- type GetMyGroupsResult
- type InlineKeyboard
- type InlineKeyboardButton
- type KappelaError
- type LeaveChatParams
- type LeaveChatResult
- type Message
- type MessageStatus
- type MessageType
- type MessagesResource
- func (r *MessagesResource) Delete(ctx context.Context, params DeleteMessageParams) (*DeleteResult, error)
- func (r *MessagesResource) Edit(ctx context.Context, params EditMessageParams) (*EditMessageResult, error)
- func (r *MessagesResource) Send(ctx context.Context, params SendMessageParams) (*SendResult, error)
- func (r *MessagesResource) SendAudio(ctx context.Context, params SendMediaParams) (*SendMediaResult, error)
- func (r *MessagesResource) SendCarousel(ctx context.Context, params SendCarouselParams) (*SendCarouselResult, error)
- func (r *MessagesResource) SendDocument(ctx context.Context, params SendMediaParams) (*SendMediaResult, error)
- func (r *MessagesResource) SendPhoto(ctx context.Context, params SendMediaParams) (*SendMediaResult, error)
- func (r *MessagesResource) SendTyping(ctx context.Context, params SendTypingParams) (*TypingResult, error)
- func (r *MessagesResource) SendVideo(ctx context.Context, params SendMediaParams) (*SendMediaResult, error)
- type Participant
- type ParticipantRole
- type PrivacySetting
- type PromoteChatMemberParams
- type PromoteChatMemberResult
- type PromoteCommunityMemberParams
- type RemoveCommunityGroupParams
- type ReplyKeyboard
- type ReplyKeyboardButton
- type ReplySnapshot
- type RevokeChatInviteLinkParams
- type RevokeChatInviteLinkResult
- type RevokeCommunityInviteLinkParams
- type ScrollKeyboard
- type ScrollKeyboardButton
- type SendCarouselParams
- type SendCarouselResult
- type SendMediaParams
- type SendMediaResult
- type SendMessageParams
- type SendResult
- type SendTypingParams
- type SetWebhookParams
- type StoriesResource
- func (r *StoriesResource) Create(ctx context.Context, params CreateStoryParams) (*Story, error)
- func (r *StoriesResource) Delete(ctx context.Context, storyID string) (*StoryActionResult, error)
- func (r *StoriesResource) Get(ctx context.Context, storyID string) (*Story, error)
- func (r *StoriesResource) GetPreferences(ctx context.Context) (*StoryPreferences, error)
- func (r *StoriesResource) GetViewers(ctx context.Context, storyID string) ([]StoryView, error)
- func (r *StoriesResource) List(ctx context.Context) ([]Story, error)
- func (r *StoriesResource) ListMine(ctx context.Context) ([]Story, error)
- func (r *StoriesResource) SetPreferences(ctx context.Context, prefs StoryPreferences) (*StoryActionResult, error)
- func (r *StoriesResource) UploadMedia(ctx context.Context, file FileInput) (*StoryMediaUpload, error)
- func (r *StoriesResource) View(ctx context.Context, storyID string) (*StoryActionResult, error)
- type Story
- type StoryActionResult
- type StoryMediaUpload
- type StoryPreferences
- type StoryView
- type TypingResult
- type UpdateCommunityParams
- type User
- func (u *User) Connected() bool
- func (u *User) GetAutomationStatus(ctx context.Context) (*AutomationStatus, error)
- func (u *User) HandleWebhook(body []byte)
- func (u *User) OnCallbackQuery(h func(*CallbackQuery))
- func (u *User) OnConnected(h func())
- func (u *User) OnDisconnected(h func(code int, reason string))
- func (u *User) OnError(h func(error))
- func (u *User) OnMessage(h func(*Message))
- func (u *User) PauseAutomationInChat(ctx context.Context, chatID int64) (*ChatAutomationResult, error)
- func (u *User) PauseAutomations(ctx context.Context) (*AutomationStatus, error)
- func (u *User) Reply(ctx context.Context, event any, text string, opts ...SendMessageParams) (*SendResult, error)
- func (u *User) ResumeAutomationInChat(ctx context.Context, chatID int64) (*ChatAutomationResult, error)
- func (u *User) ResumeAutomations(ctx context.Context) (*AutomationStatus, error)
- func (u *User) Start()
- func (u *User) Stop()
- type UserOption
- type UserProfile
- type UserProfileResource
- type WebhookDeleteResult
- type WebhookInfo
- type WebhookSetResult
- type WebhooksResource
Constants ¶
const ( StoryImage = "image" StoryVideo = "video" StoryText = "text" StoryPoll = "poll" )
Story media types.
const ( StoryAudienceAll = "all" StoryAudienceSelected = "selected" StoryAudienceExcluded = "excluded" )
Story audiences.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AcceptCommunityInviteResult ¶ added in v0.3.0
type AcceptCommunityInviteResult struct {
CommunityID int64 `json:"community_id"`
}
AcceptCommunityInviteResult is returned by AcceptInvite.
type ActionButton ¶ added in v0.7.0
type ActionButton struct {
Label string `json:"label"`
Type ActionButtonType `json:"type"` // copy_text | external_link | internal_link | join
Value string `json:"value"`
}
ActionButton is a single button rendered at the foot of the message bubble (WhatsApp-style), distinct from inline keyboards. It performs a client-side action (copy / open / join) instead of firing a callback_query.
Set it via SendMessageParams.ActionButton. When both ActionButton and ReplyMarkup are set, ActionButton takes precedence. Label: 1–100 chars, Value: 1–2048 chars.
type ActionButtonType ¶ added in v0.7.0
type ActionButtonType = string
SendMessageParams holds the parameters for sending a text message. ActionButtonType is what tapping an ActionButton does. The meaning of Value follows it:
- "copy_text" — copies Value to the clipboard (e.g. a one-time code / OTP).
- "external_link" — opens Value (an external URL) in the in-app browser.
- "internal_link" — opens Value as an in-app deep link.
- "join" — Value is an invite link (group/channel/community); tap joins directly.
type AddChatMemberParams ¶ added in v0.2.0
AddChatMemberParams holds the parameters for adding a user to a group or channel. The bot must be admin of the conversation.
type AddChatMemberResult ¶ added in v0.2.0
type AddChatMemberResult struct {
Description string `json:"description"`
}
AddChatMemberResult is returned after successfully adding a user.
type AddCommunityGroupParams ¶ added in v0.3.0
type AddCommunityMemberParams ¶ added in v0.3.0
type AddCommunityMemberParams struct {
CommunityID int64 `json:"community_id"`
UserID string `json:"user_id"`
Role ParticipantRole `json:"role,omitempty"` // default "member"
}
type AutomationStatus ¶ added in v0.4.0
type AutomationStatus struct {
AutomationsPaused bool `json:"automations_paused"`
}
AutomationStatus reports whether an account's personal automations are paused.
type BanChatMemberParams ¶ added in v0.2.0
BanChatMemberParams holds the parameters for removing (kicking) a user. The bot must be admin. To remove itself, use LeaveChatParams instead.
type BanChatMemberResult ¶ added in v0.2.0
type BanChatMemberResult struct {
Description string `json:"description"`
}
BanChatMemberResult is returned after successfully removing a user.
type BanCommunityMemberParams ¶ added in v0.3.0
type Bot ¶
type Bot struct {
// Messages provides methods to send and manage messages.
Messages *MessagesResource
// Chats provides methods to list and iterate over chats.
Chats *ChatsResource
// Webhooks provides methods to manage webhooks.
Webhooks *WebhooksResource
// Profile provides access to the bot's own profile.
Profile *BotProfileResource
// Communities provides methods to manage communities (members, roles, invites, requests).
Communities *CommunitiesResource
// contains filtered or unexported fields
}
Bot is the Kappela bot client. Authenticate with a token from BotMother.
Example:
bot := kappelas.NewBot("YOUR_BOT_TOKEN")
bot.OnMessage(func(msg *kappelas.Message) {
bot.Messages.Send(ctx, kappelas.SendMessageParams{
ChatID: msg.ChatID,
Text: "Echo: " + *msg.Text,
})
})
bot.OnCallbackQuery(func(cb *kappelas.CallbackQuery) {
bot.Messages.Send(ctx, kappelas.SendMessageParams{
ChatID: cb.ChatID,
Text: "Button clicked: " + cb.CallbackData,
})
})
bot.Start()
select {} // keep alive
func (*Bot) GetStatus ¶ added in v0.4.0
func (b *Bot) GetStatus(ctx context.Context) (*BotPauseStatus, error)
GetStatus reports whether this bot is currently paused.
func (*Bot) HandleWebhook ¶
HandleWebhook processes a webhook payload sent by Kappela to your server. Call this inside your HTTP handler and respond 200 immediately. The same OnMessage and OnCallbackQuery handlers fire for both WS and webhook events.
Example (net/http):
http.HandleFunc("/kappela-webhook", func(w http.ResponseWriter, r *http.Request) {
body, _ := io.ReadAll(r.Body)
bot.HandleWebhook(body)
w.WriteHeader(http.StatusOK)
})
func (*Bot) OnCallbackQuery ¶
func (b *Bot) OnCallbackQuery(h func(*CallbackQuery))
OnCallbackQuery registers a handler called when a user clicks an inline button.
func (*Bot) OnConnected ¶
func (b *Bot) OnConnected(h func())
OnConnected registers a handler called when the WebSocket connects (or reconnects).
func (*Bot) OnDisconnected ¶
OnDisconnected registers a handler called when the WebSocket disconnects.
func (*Bot) Pause ¶ added in v0.4.0
func (b *Bot) Pause(ctx context.Context) (*BotPauseStatus, error)
Pause pauses this bot. While paused, the bot stops receiving incoming messages (no WS push, no webhook) and any send call is rejected with BOT_PAUSED, until Resume is called. Lets an owner stop an AI bot on demand.
func (*Bot) PauseInChat ¶ added in v0.5.0
PauseInChat pauses this bot in ONE conversation only (the bot must be a participant). The bot stops receiving messages from that conversation while it keeps working in all its other chats. Unlike Pause, this is scoped to a single conversation.
func (*Bot) Reply ¶ added in v0.2.0
func (b *Bot) Reply(ctx context.Context, event any, text string, opts ...SendMessageParams) (*SendResult, error)
Reply sends a text reply to a Message or CallbackQuery event.
- When called with a *Message — sets ChatID and ReplyToID automatically (shows a quote banner).
- When called with a *CallbackQuery — sets ChatID only (callback queries have no message ID).
Pass an optional SendMessageParams to attach a keyboard or set other options. ChatID, ReplyToID, and Text in opts are overwritten automatically.
Example:
bot.OnMessage(func(msg *kappelas.Message) {
ctx := context.Background()
bot.Reply(ctx, msg, "Got it! 👋")
// With an inline keyboard
bot.Reply(ctx, msg, "Pick one:", kappelas.SendMessageParams{
ReplyMarkup: kappelas.InlineKeyboard{
InlineKeyboard: [][]kappelas.InlineKeyboardButton{{
{Text: "✅ Oui", CallbackData: ptr("yes")},
{Text: "❌ Non", CallbackData: ptr("no")},
}},
},
})
})
bot.OnCallbackQuery(func(cb *kappelas.CallbackQuery) {
ctx := context.Background()
bot.Reply(ctx, cb, "Tu as cliqué : "+cb.CallbackData)
})
func (*Bot) Resume ¶ added in v0.4.0
func (b *Bot) Resume(ctx context.Context) (*BotPauseStatus, error)
Resume resumes this bot after Pause.
func (*Bot) ResumeInChat ¶ added in v0.5.0
ResumeInChat resumes this bot in a conversation after PauseInChat.
type BotGroupEntry ¶ added in v0.2.0
type BotGroupEntry struct {
// ChatID is the conversation ID — use this as ChatID in all API calls.
ChatID int64 `json:"chat_id"`
// Type is "group" or "channel". Never "private".
Type ChatType `json:"type"`
// Title is the group or channel name.
Title *string `json:"title"`
// ParticipantCount is the total number of members (including the bot).
ParticipantCount int `json:"participant_count"`
// BotRole is the bot's role in this conversation.
BotRole ParticipantRole `json:"bot_role"`
}
BotGroupEntry is a group or channel the bot belongs to, enriched with its role.
type BotOption ¶
type BotOption func(*botConfig)
BotOption configures a Bot.
func WithBaseURL ¶
WithBaseURL overrides the API base URL (default: https://api.kappelas.com).
func WithMaxRetries ¶
WithMaxRetries sets the maximum number of HTTP retry attempts (default: 2).
func WithTimeout ¶
WithTimeout sets the HTTP request timeout (default: 30s).
func WithWSMaxRetries ¶
WithWSMaxRetries sets the maximum WebSocket reconnect attempts (default: 12).
type BotPauseStatus ¶ added in v0.4.0
type BotPauseStatus struct {
Paused bool `json:"paused"`
}
BotPauseStatus reports whether a bot is paused.
type BotProfile ¶
type BotProfile struct {
UserID string `json:"user_id"`
Username string `json:"username"`
IsBot bool `json:"is_bot"`
About string `json:"about"`
Description string `json:"description"`
AvatarURL *string `json:"avatar_url"`
}
BotProfile is the profile returned for a bot account.
type BotProfileResource ¶
type BotProfileResource struct {
// contains filtered or unexported fields
}
BotProfileResource provides access to the bot's own profile.
func (*BotProfileResource) Get ¶
func (r *BotProfileResource) Get(ctx context.Context) (*BotProfile, error)
Get returns the bot's own profile.
type CallbackQuery ¶
type CallbackQuery struct {
ChatID int64 `json:"chat_id"`
SenderID string `json:"sender_id"`
// SenderName is the display name of the user who clicked (e.g. "Arnel LAWSON").
SenderName *string `json:"sender_name"`
SenderUsername *string `json:"sender_username"`
CallbackData string `json:"callback_data"`
SentAt int64 `json:"sent_at"`
}
CallbackQuery is fired when a user clicks an inline button.
func (*CallbackQuery) GetSenderName ¶ added in v0.2.2
func (cb *CallbackQuery) GetSenderName() string
GetSenderName returns the sender display name, or "" if absent. Use this instead of dereferencing SenderName directly to avoid nil-pointer panics.
fmt.Sprintf("Hello %s!", cb.GetSenderName()) // safe
type CarouselCard ¶
type CarouselCard struct {
ID string `json:"id"`
Title string `json:"title"`
Subtitle *string `json:"subtitle,omitempty"`
ImageURL *string `json:"image_url,omitempty"`
ButtonText *string `json:"button_text,omitempty"`
}
CarouselCard is a single card inside a carousel message.
type Chat ¶
type Chat struct {
ChatID int64 `json:"chat_id"`
ID int64 `json:"id"`
Type ChatType `json:"type"`
Title *string `json:"title"`
Participants []Participant `json:"participants"`
LastMessageAt *string `json:"last_message_at"`
CreatedAt string `json:"created_at"`
CreatedBy string `json:"created_by"`
IsPinned bool `json:"is_pinned"`
IsPremium bool `json:"is_premium"`
IsPublic bool `json:"is_public"`
OnlyAdminsCanWrite bool `json:"only_admins_can_write"`
Labels []string `json:"labels"`
Description *string `json:"description"`
AvatarURL *string `json:"avatar_url"`
}
Chat represents a Kappela conversation.
type ChatAutomationResult ¶ added in v0.5.0
type ChatAutomationResult struct {
Done bool `json:"done"`
}
ChatAutomationResult is returned by the per-conversation pause methods.
type ChatInviteLink ¶ added in v0.2.0
type ChatInviteLink struct {
// Code is the short identifier used in the URL (e.g. "aBcD123xyz").
Code string `json:"code"`
// URL is the full invite URL (e.g. "https://kappelas.com/invite/aBcD123xyz").
URL string `json:"url"`
// MaxUses is the maximum number of allowed uses (0 = unlimited).
MaxUses int `json:"max_uses"`
// UseCount is the current number of uses.
UseCount int `json:"use_count"`
// ExpiresAt is the expiry as Unix timestamp (seconds), or nil if permanent.
ExpiresAt *int64 `json:"expires_at"`
// CreatedAt is the creation time as Unix timestamp (seconds).
CreatedAt int64 `json:"created_at"`
}
ChatInviteLink describes an active invite link for a group or channel.
type ChatMemberInfo ¶ added in v0.2.0
type ChatMemberInfo struct {
UserID string `json:"user_id"`
Role ParticipantRole `json:"role"`
}
ChatMemberInfo is a minimal member record returned by GetMember and GetAdministrators.
type ChatsResource ¶
type ChatsResource struct {
// contains filtered or unexported fields
}
ChatsResource provides methods to access and manage chats.
func (*ChatsResource) AddMember ¶ added in v0.2.0
func (r *ChatsResource) AddMember(ctx context.Context, params AddChatMemberParams) (*AddChatMemberResult, error)
AddMember adds a user to a group or channel. The bot must be admin of the conversation.
Example:
result, err := bot.Chats.AddMember(ctx, kappelas.AddChatMemberParams{
ChatID: 42, UserID: "user-uuid",
})
func (*ChatsResource) BanMember ¶ added in v0.2.0
func (r *ChatsResource) BanMember(ctx context.Context, params BanChatMemberParams) (*BanChatMemberResult, error)
BanMember removes (kicks) a user from a group or channel. The bot must be admin. To remove itself, use LeaveChat instead.
Example:
result, err := bot.Chats.BanMember(ctx, kappelas.BanChatMemberParams{
ChatID: 42, UserID: "user-uuid",
})
func (*ChatsResource) CreateInviteLink ¶ added in v0.2.0
func (r *ChatsResource) CreateInviteLink(ctx context.Context, params CreateChatInviteLinkParams) (*ChatInviteLink, error)
CreateInviteLink creates an invite link for a group or channel. The bot must be admin of the conversation.
Example:
// Permanent link, unlimited uses
link, err := bot.Chats.CreateInviteLink(ctx, kappelas.CreateChatInviteLinkParams{
ChatID: 42,
})
fmt.Println(link.URL) // "https://kappelas.com/invite/aBcD123xyz"
// Single-use, expires in 24 h
link, err := bot.Chats.CreateInviteLink(ctx, kappelas.CreateChatInviteLinkParams{
ChatID: 42, MaxUses: 1, ExpiresIn: "24h",
})
func (*ChatsResource) CreateSingleUseInviteLink ¶ added in v0.2.0
func (r *ChatsResource) CreateSingleUseInviteLink(ctx context.Context, params CreateChatInviteLinkParams) (*ChatInviteLink, error)
CreateSingleUseInviteLink is a shorthand to create a single-use invite link. Equivalent to CreateInviteLink with MaxUses: 1. The bot must be admin.
Example:
link, err := bot.Chats.CreateSingleUseInviteLink(ctx, kappelas.CreateChatInviteLinkParams{
ChatID: 42,
})
func (*ChatsResource) GetAdministrators ¶ added in v0.2.0
func (r *ChatsResource) GetAdministrators(ctx context.Context, params GetChatAdministratorsParams) (*GetChatAdministratorsResult, error)
GetAdministrators returns all admins of a group or channel. The bot must be a member of the conversation.
Example:
result, err := bot.Chats.GetAdministrators(ctx, kappelas.GetChatAdministratorsParams{ChatID: 42})
for _, admin := range result.Admins {
fmt.Println(admin.UserID, admin.Role)
}
func (*ChatsResource) GetInviteLinks ¶ added in v0.2.0
func (r *ChatsResource) GetInviteLinks(ctx context.Context, params GetChatInviteLinksParams) (*GetChatInviteLinksResult, error)
GetInviteLinks returns all active invite links for a group or channel. The bot must be admin.
Example:
result, err := bot.Chats.GetInviteLinks(ctx, kappelas.GetChatInviteLinksParams{ChatID: 42})
for _, link := range result.InviteLinks {
fmt.Printf("%s — %d/%d uses\n", link.URL, link.UseCount, link.MaxUses)
}
func (*ChatsResource) GetMember ¶ added in v0.2.0
func (r *ChatsResource) GetMember(ctx context.Context, params GetChatMemberParams) (*ChatMemberInfo, error)
GetMember returns info for a specific member (UserID + Role). The bot must be a member of the conversation. Returns ErrCodeNotFound if the user is not in the conversation.
Example:
member, err := bot.Chats.GetMember(ctx, kappelas.GetChatMemberParams{
ChatID: 42, UserID: "user-uuid",
})
fmt.Println(member.Role) // "admin" | "member"
func (*ChatsResource) GetMyGroups ¶ added in v0.2.0
func (r *ChatsResource) GetMyGroups(ctx context.Context) (*GetMyGroupsResult, error)
GetMyGroups returns every group and channel the bot is a member of, together with the bot's own role in each.
Useful to discover which groups the bot can manage (e.g. create invite links).
Example:
result, err := bot.Chats.GetMyGroups(ctx)
for _, g := range result.Groups {
fmt.Printf("%d (%s) %q → %s\n", g.ChatID, g.Type, g.Title, g.BotRole)
if g.BotRole == kappelas.ParticipantRoleAdmin {
// bot can create invite links, manage members…
}
}
func (*ChatsResource) Iterate ¶
Iterate calls fn for every chat, handling pagination automatically. Return false from fn to stop iteration early.
Example:
err := bot.Chats.Iterate(ctx, 50, func(chat *kappelas.Chat) bool {
fmt.Println(chat.ChatID, chat.Type)
return true // continue
})
func (*ChatsResource) LeaveChat ¶ added in v0.2.0
func (r *ChatsResource) LeaveChat(ctx context.Context, params LeaveChatParams) (*LeaveChatResult, error)
LeaveChat makes the bot leave a group or channel.
Example:
result, err := bot.Chats.LeaveChat(ctx, kappelas.LeaveChatParams{ChatID: 42})
func (*ChatsResource) List ¶
func (r *ChatsResource) List(ctx context.Context, params GetChatsParams) (ChatsResult, error)
List returns a paginated list of chats accessible to this bot or user.
func (*ChatsResource) PromoteMember ¶ added in v0.2.0
func (r *ChatsResource) PromoteMember(ctx context.Context, params PromoteChatMemberParams) (*PromoteChatMemberResult, error)
PromoteMember promotes or demotes a member. The bot must be admin.
- Role: ParticipantRoleAdmin — grants admin rights
- Role: ParticipantRoleMember — revokes admin rights
Example:
// Promote to admin
bot.Chats.PromoteMember(ctx, kappelas.PromoteChatMemberParams{
ChatID: 42,
UserID: "user-uuid",
Role: kappelas.ParticipantRoleAdmin,
})
func (*ChatsResource) RevokeInviteLink ¶ added in v0.2.0
func (r *ChatsResource) RevokeInviteLink(ctx context.Context, params RevokeChatInviteLinkParams) (*RevokeChatInviteLinkResult, error)
RevokeInviteLink revokes an active invite link so it can no longer be used. The bot must be admin.
Example:
result, err := bot.Chats.RevokeInviteLink(ctx, kappelas.RevokeChatInviteLinkParams{
ChatID: 42, Code: "aBcD123xyz",
})
type ChatsResult ¶
ChatsResult is the paginated response from the list chats endpoint.
type CommunitiesResource ¶ added in v0.3.0
type CommunitiesResource struct {
// contains filtered or unexported fields
}
CommunitiesResource provides methods to manage communities (members, roles, invites, join/group requests). A bot can administer a community only if it is admin of that community.
To make someone (a person OR a bot) a community admin, the flow is two steps — add as member first, then promote:
bot.Communities.AddMember(ctx, kappelas.AddCommunityMemberParams{CommunityID: 7, UserID: "uuid", Role: kappelas.ParticipantRoleMember})
bot.Communities.PromoteMember(ctx, kappelas.PromoteCommunityMemberParams{CommunityID: 7, UserID: "uuid", Role: kappelas.ParticipantRoleAdmin})
func (*CommunitiesResource) AcceptInvite ¶ added in v0.3.0
func (r *CommunitiesResource) AcceptInvite(ctx context.Context, params CommunityInviteCodeParams) (*AcceptCommunityInviteResult, error)
AcceptInvite makes the bot join a community via an invite code.
func (*CommunitiesResource) AddGroup ¶ added in v0.3.0
func (r *CommunitiesResource) AddGroup(ctx context.Context, params AddCommunityGroupParams) (*CommunityActionResult, error)
AddGroup links a group to the community (the bot must be community admin AND group admin).
func (*CommunitiesResource) AddMember ¶ added in v0.3.0
func (r *CommunitiesResource) AddMember(ctx context.Context, params AddCommunityMemberParams) (*CommunityActionResult, error)
AddMember adds a member (person or bot). The bot must be community admin.
func (*CommunitiesResource) ApproveGroupRequest ¶ added in v0.3.0
func (r *CommunitiesResource) ApproveGroupRequest(ctx context.Context, params CommunityRequestActionParams) (*CommunityActionResult, error)
ApproveGroupRequest approves a group request (links the group). Admin.
func (*CommunitiesResource) ApproveJoinRequest ¶ added in v0.3.0
func (r *CommunitiesResource) ApproveJoinRequest(ctx context.Context, params CommunityRequestActionParams) (*CommunityActionResult, error)
ApproveJoinRequest approves a join request. Admin.
func (*CommunitiesResource) BanMember ¶ added in v0.3.0
func (r *CommunitiesResource) BanMember(ctx context.Context, params BanCommunityMemberParams) (*CommunityActionResult, error)
BanMember removes a member. The bot must be community admin (or removes itself).
func (*CommunitiesResource) Create ¶ added in v0.3.0
func (r *CommunitiesResource) Create(ctx context.Context, params CreateCommunityParams) (*Community, error)
Create creates a community (the bot becomes admin).
func (*CommunitiesResource) CreateInviteLink ¶ added in v0.3.0
func (r *CommunitiesResource) CreateInviteLink(ctx context.Context, params CreateCommunityInviteLinkParams) (*CommunityInvite, error)
CreateInviteLink creates an invite link. The bot must be community admin.
func (*CommunitiesResource) Delete ¶ added in v0.3.0
func (r *CommunitiesResource) Delete(ctx context.Context, params GetCommunityParams) (*CommunityActionResult, error)
Delete deletes a community (admin).
func (*CommunitiesResource) Get ¶ added in v0.3.0
func (r *CommunitiesResource) Get(ctx context.Context, params GetCommunityParams) (*CommunityDetail, error)
Get returns the full detail of a community (infos + groups + members).
func (*CommunitiesResource) GetGroupRequests ¶ added in v0.3.0
func (r *CommunitiesResource) GetGroupRequests(ctx context.Context, params GetCommunityParams) ([]CommunityGroupRequest, error)
GetGroupRequests returns pending requests from groups to join the community. Admin.
func (*CommunitiesResource) GetInviteLinks ¶ added in v0.3.0
func (r *CommunitiesResource) GetInviteLinks(ctx context.Context, params GetCommunityParams) (*GetCommunityInviteLinksResult, error)
GetInviteLinks returns the active invite links. The bot must be community admin.
func (*CommunitiesResource) GetJoinRequests ¶ added in v0.3.0
func (r *CommunitiesResource) GetJoinRequests(ctx context.Context, params GetCommunityParams) ([]CommunityJoinRequest, error)
GetJoinRequests returns pending join requests (approval-required mode). Admin.
func (*CommunitiesResource) Join ¶ added in v0.3.0
func (r *CommunitiesResource) Join(ctx context.Context, params GetCommunityParams) (*CommunityActionResult, error)
Join joins a community. Public → member immediately; approval-required → the result has Pending = true (request queued).
func (*CommunitiesResource) Leave ¶ added in v0.3.0
func (r *CommunitiesResource) Leave(ctx context.Context, params GetCommunityParams) (*CommunityActionResult, error)
Leave makes the bot leave the community.
func (*CommunitiesResource) List ¶ added in v0.3.0
func (r *CommunitiesResource) List(ctx context.Context) (GetMyCommunitiesResult, error)
List returns the communities the bot is a member of (each with the bot's Role).
func (*CommunitiesResource) ListAdmin ¶ added in v0.3.0
func (r *CommunitiesResource) ListAdmin(ctx context.Context) ([]Community, error)
ListAdmin returns only the communities where the bot is community admin.
Note: this is the role IN THE COMMUNITY — being admin of a group attached to a community does NOT make the bot admin of the community.
func (*CommunitiesResource) PreviewInvite ¶ added in v0.3.0
func (r *CommunitiesResource) PreviewInvite(ctx context.Context, params CommunityInviteCodeParams) (*CommunityInvitePreview, error)
PreviewInvite returns the public preview of a community from an invite code.
func (*CommunitiesResource) PromoteMember ¶ added in v0.3.0
func (r *CommunitiesResource) PromoteMember(ctx context.Context, params PromoteCommunityMemberParams) (*CommunityActionResult, error)
PromoteMember promotes ("admin") or demotes ("member") a member. The bot must be community admin. The member must already exist (add it first).
func (*CommunitiesResource) RejectGroupRequest ¶ added in v0.3.0
func (r *CommunitiesResource) RejectGroupRequest(ctx context.Context, params CommunityRequestActionParams) (*CommunityActionResult, error)
RejectGroupRequest rejects a group request. Admin.
func (*CommunitiesResource) RejectJoinRequest ¶ added in v0.3.0
func (r *CommunitiesResource) RejectJoinRequest(ctx context.Context, params CommunityRequestActionParams) (*CommunityActionResult, error)
RejectJoinRequest rejects a join request. Admin.
func (*CommunitiesResource) RemoveGroup ¶ added in v0.3.0
func (r *CommunitiesResource) RemoveGroup(ctx context.Context, params RemoveCommunityGroupParams) (*CommunityActionResult, error)
RemoveGroup unlinks a group from the community (community admin OR group admin).
func (*CommunitiesResource) RevokeInviteLink ¶ added in v0.3.0
func (r *CommunitiesResource) RevokeInviteLink(ctx context.Context, params RevokeCommunityInviteLinkParams) (*CommunityActionResult, error)
RevokeInviteLink revokes an invite link. The bot must be community admin.
func (*CommunitiesResource) Update ¶ added in v0.3.0
func (r *CommunitiesResource) Update(ctx context.Context, params UpdateCommunityParams) (*Community, error)
Update modifies a community (admin). Only non-nil fields are changed.
type Community ¶ added in v0.3.0
type Community struct {
ID int64 `json:"id"`
Name string `json:"name"`
Description *string `json:"description"`
AvatarURL *string `json:"avatar_url"`
CreatedBy string `json:"created_by"`
AnnouncementChannelID *int64 `json:"announcement_channel_id"`
RequiresApproval bool `json:"requires_approval"`
CreatedAt string `json:"created_at"` // ISO 8601
// Role of the bot/user IN THE COMMUNITY ("member"|"admin"). Set by List() only.
// Note: being admin of a GROUP attached to a community does NOT make you admin
// of the community (distinct scopes).
Role ParticipantRole `json:"role,omitempty"`
}
Community is a community the bot/user belongs to.
type CommunityActionResult ¶ added in v0.3.0
CommunityActionResult is returned by actions without a body. Done is true on success; Pending is true when a join is queued for approval.
type CommunityDetail ¶ added in v0.3.0
type CommunityDetail struct {
Community Community `json:"community"`
Groups []CommunityGroup `json:"groups"`
Members []CommunityMember `json:"members"`
}
CommunityDetail is the full view returned by Get().
type CommunityGroup ¶ added in v0.3.0
type CommunityGroup struct {
ID int64 `json:"id"`
Type string `json:"type"`
Title *string `json:"title"`
AvatarURL *string `json:"avatar_url"`
Joined bool `json:"joined"`
Pending bool `json:"pending"`
ParticipantsCount int `json:"participants_count"`
}
CommunityGroup is a group/channel linked to a community.
type CommunityGroupRequest ¶ added in v0.3.0
type CommunityGroupRequest struct {
ID int64 `json:"id"`
CommunityID int64 `json:"community_id"`
ConversationID int64 `json:"conversation_id"`
GroupName string `json:"group_name"`
RequestedBy string `json:"requested_by"`
Status string `json:"status"`
CreatedAt string `json:"created_at"`
}
CommunityGroupRequest is a pending request from a group to join a community.
type CommunityInvite ¶ added in v0.3.0
type CommunityInvite struct {
Code string `json:"code"`
CommunityID int64 `json:"community_id"`
CreatedBy string `json:"created_by"`
MaxUses int `json:"max_uses"` // 0 = unlimited, 1+ = capped
UseCount int `json:"use_count"`
ExpiresAt *string `json:"expires_at"` // ISO 8601 or nil if permanent
RevokedAt *string `json:"revoked_at"` // ISO 8601 or nil if active
CreatedAt string `json:"created_at"`
}
CommunityInvite is an invite link to a community.
type CommunityInviteCodeParams ¶ added in v0.3.0
type CommunityInviteCodeParams struct {
Code string `json:"code"`
}
type CommunityInvitePreview ¶ added in v0.3.0
type CommunityInvitePreview struct {
Code string `json:"code"`
CommunityID int64 `json:"community_id"`
CommunityName string `json:"community_name"`
MemberCount int `json:"member_count"`
ExpiresAt *string `json:"expires_at"`
AvatarURL *string `json:"avatar_url"`
Description *string `json:"description"`
}
CommunityInvitePreview is the public preview of a community via an invite code.
type CommunityJoinRequest ¶ added in v0.3.0
type CommunityJoinRequest struct {
ID int64 `json:"id"`
CommunityID int64 `json:"community_id"`
UserID string `json:"user_id"`
Status string `json:"status"`
CreatedAt string `json:"created_at"`
RequesterName string `json:"requester_name,omitempty"`
RequesterAvatarURL *string `json:"requester_avatar_url,omitempty"`
}
CommunityJoinRequest is a pending request from a user to join a community.
type CommunityMember ¶ added in v0.3.0
type CommunityMember struct {
CommunityID int64 `json:"community_id"`
UserID string `json:"user_id"`
Role ParticipantRole `json:"role"`
JoinedAt string `json:"joined_at"`
Name string `json:"name,omitempty"`
AvatarURL *string `json:"avatar_url,omitempty"`
}
CommunityMember is a member of a community (enriched with name/avatar by Get()).
type CommunityRequestActionParams ¶ added in v0.3.0
type CreateChatInviteLinkParams ¶ added in v0.2.0
type CreateChatInviteLinkParams struct {
ChatID int64 `json:"chat_id"`
// MaxUses is 0 for unlimited, or a positive number to cap uses.
MaxUses int `json:"max_uses,omitempty"`
// ExpiresIn controls expiry: "1h", "24h", "7d", "30d", or "never" (default).
ExpiresIn string `json:"expires_in,omitempty"`
}
CreateChatInviteLinkParams holds the parameters for creating an invite link. The bot must be admin of the conversation.
type CreateCommunityInviteLinkParams ¶ added in v0.3.0
type CreateCommunityParams ¶ added in v0.3.0
type CreateStoryParams ¶ added in v0.6.0
type CreateStoryParams struct {
// Type is one of StoryImage, StoryVideo, StoryText, StoryPoll.
Type string
// Media is the image/video file — uploaded automatically by the SDK. Used for
// image/video stories when MediaID is empty. Ignored for text/poll.
Media *FileInput
// MediaID is an alternative to Media: an already-uploaded media id.
MediaID string
Caption string
// Link is a clickable CTA link shown over the story in the Kappela apps. When
// set, the SDK encodes the caption as a JSON envelope ({text, link, linkLabel})
// — the format the apps read (there is no separate backend field).
Link string
// LinkLabel is an optional label for the CTA link (e.g. "Shop now"). Requires Link.
LinkLabel string
// Audience is one of StoryAudienceAll (default), StoryAudienceSelected, StoryAudienceExcluded.
Audience string
// AudienceUserIDs is required when Audience is selected or excluded.
AudienceUserIDs []string
}
CreateStoryParams holds the parameters for creating a story.
type DeleteMessageParams ¶
type DeleteMessageParams struct {
ChatID int64 `json:"chat_id,omitempty"`
UserID string `json:"user_id,omitempty"`
MessageID int64 `json:"message_id"`
}
DeleteMessageParams holds the parameters for deleting a message.
Recipient — set EITHER ChatID OR UserID (UUID); the conversation must exist.
type DeleteResult ¶
type DeleteResult struct {
Deleted bool `json:"deleted"`
}
DeleteResult is returned by the deleteMessage endpoint.
type EditMessageParams ¶
type EditMessageParams struct {
ChatID int64 `json:"chat_id,omitempty"`
UserID string `json:"user_id,omitempty"`
MessageID int64 `json:"message_id"`
NewText string `json:"new_text,omitempty"`
NewExtraData json.RawMessage `json:"new_extra_data,omitempty"`
}
EditMessageParams holds the parameters for editing a message.
Recipient — set EITHER ChatID OR UserID (UUID). With UserID the private conversation must already exist (you are editing an existing message).
type EditMessageResult ¶
EditMessageResult is returned after editing a message.
type ErrorCode ¶
type ErrorCode string
ErrorCode is the machine-readable error code returned by the Kappela API.
const ( ErrCodeForbidden ErrorCode = "FORBIDDEN" ErrCodeNotFound ErrorCode = "NOT_FOUND" ErrCodeInvalidField ErrorCode = "INVALID_FIELD" ErrCodeMissingField ErrorCode = "MISSING_FIELD" ErrCodeInternalError ErrorCode = "INTERNAL_ERROR" ErrCodeConflict ErrorCode = "CONFLICT" ErrCodeMethodNotAllowed ErrorCode = "METHOD_NOT_ALLOWED" ErrCodeInvalidPath ErrorCode = "INVALID_PATH" ErrCodeUpstreamError ErrorCode = "UPSTREAM_ERROR" )
type GetChatAdministratorsParams ¶ added in v0.2.0
type GetChatAdministratorsParams struct {
ChatID int64 `json:"chat_id"`
}
GetChatAdministratorsParams holds the parameters for fetching chat admins.
type GetChatAdministratorsResult ¶ added in v0.2.0
type GetChatAdministratorsResult struct {
Admins []ChatMemberInfo `json:"admins"`
}
GetChatAdministratorsResult contains all admins of a group or channel.
type GetChatInviteLinksParams ¶ added in v0.2.0
type GetChatInviteLinksParams struct {
ChatID int64 `json:"chat_id"`
}
GetChatInviteLinksParams holds the parameters for listing invite links.
type GetChatInviteLinksResult ¶ added in v0.2.0
type GetChatInviteLinksResult struct {
InviteLinks []ChatInviteLink `json:"invite_links"`
}
GetChatInviteLinksResult contains all active invite links for a group or channel.
type GetChatMemberParams ¶ added in v0.2.0
GetChatMemberParams holds the parameters for looking up a single member.
type GetChatsParams ¶
GetChatsParams holds the parameters for listing chats.
type GetCommunityInviteLinksResult ¶ added in v0.3.0
type GetCommunityInviteLinksResult struct {
Invites []CommunityInvite `json:"invites"`
}
GetCommunityInviteLinksResult wraps the invite links list.
type GetCommunityParams ¶ added in v0.3.0
type GetCommunityParams struct {
CommunityID int64 `json:"community_id"`
}
type GetMyCommunitiesResult ¶ added in v0.3.0
type GetMyCommunitiesResult struct {
Communities []Community `json:"communities"`
}
GetMyCommunitiesResult wraps the communities list.
type GetMyGroupsResult ¶ added in v0.2.0
type GetMyGroupsResult struct {
Groups []BotGroupEntry `json:"groups"`
}
GetMyGroupsResult holds the list of groups and channels the bot belongs to.
type InlineKeyboard ¶
type InlineKeyboard struct {
InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard"`
}
InlineKeyboard renders buttons attached to a message.
type InlineKeyboardButton ¶
type InlineKeyboardButton struct {
Text string `json:"text"`
CallbackData *string `json:"callback_data,omitempty"`
URL *string `json:"url,omitempty"`
}
InlineKeyboardButton is a button inside an inline keyboard.
type KappelaError ¶
type KappelaError struct {
// Message is the human-readable error description from the API.
Message string
// Code is the machine-readable error code.
Code ErrorCode
// Status is the HTTP status code.
Status int
// RequestID can be quoted when contacting support.
RequestID string
}
KappelaError is returned when the Kappela API responds with an error.
func (*KappelaError) Error ¶
func (e *KappelaError) Error() string
type LeaveChatParams ¶ added in v0.2.0
type LeaveChatParams struct {
ChatID int64 `json:"chat_id"`
}
LeaveChatParams holds the parameters for the bot to leave a group or channel.
type LeaveChatResult ¶ added in v0.2.0
type LeaveChatResult struct {
Description string `json:"description"`
}
LeaveChatResult is returned after the bot leaves.
type Message ¶
type Message struct {
ID int64 `json:"id"`
ChatID int64 `json:"chat_id"`
// ChatType is the type of conversation ("private", "group", "channel").
// Always present on WS and webhook events; may be absent on history API results.
ChatType *ChatType `json:"chat_type,omitempty"`
SenderID *string `json:"sender_id"`
Type MessageType `json:"type"`
Text *string `json:"text"`
MediaID *string `json:"media_id"`
ExtraData json.RawMessage `json:"extra_data"`
Status MessageStatus `json:"status"`
EditedAt *int64 `json:"edited_at"`
DeletedAt *int64 `json:"deleted_at"`
CreatedAt int64 `json:"created_at"`
ReplyToID *int64 `json:"reply_to_id"`
ReplyToSnapshot *ReplySnapshot `json:"reply_to_snapshot"`
Mentions []string `json:"mentions"`
ForwardedFrom json.RawMessage `json:"forwarded_from"`
ExpiresAt *int64 `json:"expires_at"`
// SenderName is the display name of the sender.
// Only present on messages in groups and channels — absent in private chats.
SenderName *string `json:"sender_name,omitempty"`
SenderAvatarURL *string `json:"sender_avatar_url,omitempty"`
ClientMsgID string `json:"client_msg_id,omitempty"`
Width *int `json:"width,omitempty"`
Height *int `json:"height,omitempty"`
}
Message represents a Kappela chat message.
func (*Message) GetSenderName ¶ added in v0.2.2
GetSenderName returns the sender display name, or "" if absent. Use this instead of dereferencing SenderName directly to avoid nil-pointer panics.
fmt.Sprintf("Hello %s!", msg.GetSenderName()) // safe
type MessageStatus ¶
type MessageStatus string
MessageStatus is the delivery status of a message.
const ( MessageStatusSent MessageStatus = "sent" MessageStatusDelivered MessageStatus = "delivered" MessageStatusRead MessageStatus = "read" )
type MessageType ¶
type MessageType string
MessageType is the content type of a message.
const ( MessageTypeText MessageType = "text" MessageTypeImage MessageType = "image" MessageTypeVideo MessageType = "video" MessageTypeAudio MessageType = "audio" MessageTypeDocument MessageType = "document" MessageTypeSystem MessageType = "system" MessageTypePoll MessageType = "poll" MessageTypeSticker MessageType = "sticker" MessageTypeLocation MessageType = "location" MessageTypeContact MessageType = "contact" )
type MessagesResource ¶
type MessagesResource struct {
// contains filtered or unexported fields
}
MessagesResource provides methods to send and manage messages.
func (*MessagesResource) Delete ¶
func (r *MessagesResource) Delete(ctx context.Context, params DeleteMessageParams) (*DeleteResult, error)
Delete deletes a message sent by this bot or user.
func (*MessagesResource) Edit ¶
func (r *MessagesResource) Edit(ctx context.Context, params EditMessageParams) (*EditMessageResult, error)
Edit edits the text or inline keyboard of a message sent by this bot or user.
func (*MessagesResource) Send ¶
func (r *MessagesResource) Send(ctx context.Context, params SendMessageParams) (*SendResult, error)
Send sends a text message, with optional inline buttons or keyboard.
func (*MessagesResource) SendAudio ¶
func (r *MessagesResource) SendAudio(ctx context.Context, params SendMediaParams) (*SendMediaResult, error)
SendAudio sends an audio file.
func (*MessagesResource) SendCarousel ¶
func (r *MessagesResource) SendCarousel(ctx context.Context, params SendCarouselParams) (*SendCarouselResult, error)
SendCarousel sends a product or card carousel.
func (*MessagesResource) SendDocument ¶
func (r *MessagesResource) SendDocument(ctx context.Context, params SendMediaParams) (*SendMediaResult, error)
SendDocument sends a document or generic file.
func (*MessagesResource) SendPhoto ¶
func (r *MessagesResource) SendPhoto(ctx context.Context, params SendMediaParams) (*SendMediaResult, error)
SendPhoto sends a photo (image file).
func (*MessagesResource) SendTyping ¶
func (r *MessagesResource) SendTyping(ctx context.Context, params SendTypingParams) (*TypingResult, error)
SendTyping shows or hides the typing indicator in a chat. IsTyping defaults to true when not set.
func (*MessagesResource) SendVideo ¶
func (r *MessagesResource) SendVideo(ctx context.Context, params SendMediaParams) (*SendMediaResult, error)
SendVideo sends a video file.
type Participant ¶
type Participant struct {
ID string `json:"id"`
Nom string `json:"nom"`
IsBot bool `json:"is_bot"`
IsPremium bool `json:"is_premium"`
AvatarURL *string `json:"avatar_url"`
// Role is the member's role in the conversation.
// Present on groups and channels; absent on private chats.
Role *ParticipantRole `json:"role,omitempty"`
}
Participant is a member of a chat.
type ParticipantRole ¶ added in v0.2.0
type ParticipantRole string
ParticipantRole is the role of a member in a group or channel.
const ( ParticipantRoleMember ParticipantRole = "member" ParticipantRoleAdmin ParticipantRole = "admin" )
type PrivacySetting ¶
type PrivacySetting string
PrivacySetting is a user privacy configuration value.
const ( PrivacyEveryone PrivacySetting = "everyone" PrivacyContacts PrivacySetting = "contacts" PrivacyNobody PrivacySetting = "nobody" )
type PromoteChatMemberParams ¶ added in v0.2.0
type PromoteChatMemberParams struct {
ChatID int64 `json:"chat_id"`
UserID string `json:"user_id"`
// Role: ParticipantRoleAdmin promotes, ParticipantRoleMember demotes.
Role ParticipantRole `json:"role"`
}
PromoteChatMemberParams holds the parameters for changing a member's role. The bot must be admin.
type PromoteChatMemberResult ¶ added in v0.2.0
type PromoteChatMemberResult struct {
UserID string `json:"user_id"`
Role ParticipantRole `json:"role"`
}
PromoteChatMemberResult is returned after a role change.
type PromoteCommunityMemberParams ¶ added in v0.3.0
type PromoteCommunityMemberParams struct {
CommunityID int64 `json:"community_id"`
UserID string `json:"user_id"`
Role ParticipantRole `json:"role"` // "admin" promotes, "member" demotes
}
type RemoveCommunityGroupParams ¶ added in v0.3.0
type ReplyKeyboard ¶
type ReplyKeyboard struct {
Keyboard [][]ReplyKeyboardButton `json:"keyboard"`
}
ReplyKeyboard renders a custom keyboard shown below the message input field.
type ReplyKeyboardButton ¶ added in v0.2.0
type ReplyKeyboardButton struct {
// Text is the label shown on the button.
Text string
// CallbackData is the value sent to the webhook when the button is pressed.
// Defaults to Text when empty.
CallbackData string
}
ReplyKeyboardButton is a single button in a reply or scroll keyboard.
Short form — label and callback value are identical:
ReplyKeyboardButton{Text: "Option A"}
Long form — different label and callback value:
ReplyKeyboardButton{Text: "✅ Confirmer", CallbackData: "confirm_yes"}
func (ReplyKeyboardButton) MarshalJSON ¶ added in v0.2.0
func (b ReplyKeyboardButton) MarshalJSON() ([]byte, error)
MarshalJSON serialises as a plain string when CallbackData is empty or equals Text, and as {"text":…,"callback_data":…} when they differ.
type ReplySnapshot ¶
type ReplySnapshot struct {
MessageID int64 `json:"message_id"`
SenderID *string `json:"sender_id"`
Type MessageType `json:"type"`
Text *string `json:"text"`
MediaID *string `json:"media_id"`
}
ReplySnapshot is a lightweight snapshot of the message being replied to.
type RevokeChatInviteLinkParams ¶ added in v0.2.0
type RevokeChatInviteLinkParams struct {
ChatID int64 `json:"chat_id"`
// Code is the code field of the link to revoke.
Code string `json:"code"`
}
RevokeChatInviteLinkParams holds the parameters for revoking an invite link.
type RevokeChatInviteLinkResult ¶ added in v0.2.0
RevokeChatInviteLinkResult is returned after revoking a link.
type RevokeCommunityInviteLinkParams ¶ added in v0.3.0
type ScrollKeyboard ¶
type ScrollKeyboard struct {
ScrollKeyboard []ScrollKeyboardButton `json:"scroll_keyboard"`
}
ScrollKeyboard renders a horizontally scrollable chip bar below the message input.
type ScrollKeyboardButton ¶ added in v0.2.0
type ScrollKeyboardButton = ReplyKeyboardButton
ScrollKeyboardButton is a button in a scroll (horizontal chips) keyboard. Same short/long form as ReplyKeyboardButton.
type SendCarouselParams ¶
type SendCarouselParams struct {
ChatID int64 `json:"chat_id,omitempty"`
UserID string `json:"user_id,omitempty"`
Text string `json:"text,omitempty"`
Carousel []CarouselCard `json:"carousel"`
// QuickReplyButtons are shown as chips below the carousel.
// Accepts short form {Text: "label"} or long form {Text: "label", CallbackData: "value"}.
QuickReplyButtons []ScrollKeyboardButton `json:"quick_reply_buttons,omitempty"`
ReplyToID *int64 `json:"reply_to_id,omitempty"`
DeletePrevious bool `json:"delete_previous,omitempty"`
}
SendCarouselParams holds the parameters for sending a product carousel.
Recipient — set EITHER ChatID OR UserID (UUID); see SendMessageParams.
type SendCarouselResult ¶
type SendCarouselResult struct {
MessageID int64 `json:"message_id"`
CreatedAt int64 `json:"created_at"`
Type string `json:"type"`
}
SendCarouselResult is returned after sending a carousel.
type SendMediaParams ¶
type SendMediaParams struct {
ChatID int64
UserID string
File FileInput
Caption string
ReplyToID *int64
DeletePrevious bool
// ReplyMarkup accepts InlineKeyboard, ReplyKeyboard, or ScrollKeyboard.
ReplyMarkup any
}
SendMediaParams holds the parameters for sending a photo, video, document, or audio.
Recipient — set EITHER ChatID OR UserID (UUID); see SendMessageParams.
type SendMediaResult ¶
type SendMediaResult struct {
MessageID int64 `json:"message_id"`
CreatedAt int64 `json:"created_at"`
MediaID string `json:"media_id"`
}
SendMediaResult is returned after sending a media message.
type SendMessageParams ¶
type SendMessageParams struct {
ChatID int64 `json:"chat_id,omitempty"`
UserID string `json:"user_id,omitempty"`
Text string `json:"text"`
// ReplyMarkup accepts InlineKeyboard, ReplyKeyboard, or ScrollKeyboard.
ReplyMarkup any `json:"reply_markup,omitempty"`
// ActionButton renders a copy/link/join button at the foot of the bubble.
ActionButton *ActionButton `json:"action_button,omitempty"`
ReplyToID *int64 `json:"reply_to_id,omitempty"`
DeletePrevious bool `json:"delete_previous,omitempty"`
}
SendMessageParams holds the parameters for sending a text message.
Recipient — set EITHER ChatID OR UserID (UUID). With UserID the message is routed to your 1-to-1 private chat with that user: for a Bot the conversation must already exist (FORBIDDEN otherwise); for a User it is created if needed.
type SendResult ¶
SendResult is returned after sending a text message.
type SendTypingParams ¶
type SendTypingParams struct {
ChatID int64 `json:"chat_id,omitempty"`
UserID string `json:"user_id,omitempty"`
IsTyping *bool `json:"is_typing,omitempty"`
}
SendTypingParams holds the parameters for the typing indicator. IsTyping defaults to true when nil (show indicator). Set to false to hide it.
Recipient — set EITHER ChatID OR UserID (UUID); see SendMessageParams.
type SetWebhookParams ¶
SetWebhookParams holds the parameters for registering a webhook.
type StoriesResource ¶ added in v0.6.0
type StoriesResource struct {
// contains filtered or unexported fields
}
StoriesResource provides methods to create and manage stories (ephemeral, 24 h).
Stories are a user-only feature (their audience is based on your private conversation contacts) — available on User, not Bot. For image/video stories, the SDK uploads the file automatically (like Messages.SendPhoto) and uses the resulting media id.
func (*StoriesResource) Create ¶ added in v0.6.0
func (r *StoriesResource) Create(ctx context.Context, params CreateStoryParams) (*Story, error)
Create creates a story. For image/video, pass Media (uploaded automatically) or a pre-uploaded MediaID. For text/poll, just set Caption.
func (*StoriesResource) Delete ¶ added in v0.6.0
func (r *StoriesResource) Delete(ctx context.Context, storyID string) (*StoryActionResult, error)
Delete deletes one of your stories.
func (*StoriesResource) Get ¶ added in v0.6.0
Get returns a single story by id (audience-checked server-side).
func (*StoriesResource) GetPreferences ¶ added in v0.6.0
func (r *StoriesResource) GetPreferences(ctx context.Context) (*StoryPreferences, error)
GetPreferences returns your default story audience preference.
func (*StoriesResource) GetViewers ¶ added in v0.6.0
GetViewers lists who viewed one of your stories (owner only).
func (*StoriesResource) List ¶ added in v0.6.0
func (r *StoriesResource) List(ctx context.Context) ([]Story, error)
List returns the feed of your contacts' active stories.
func (*StoriesResource) ListMine ¶ added in v0.6.0
func (r *StoriesResource) ListMine(ctx context.Context) ([]Story, error)
ListMine returns your own stories.
func (*StoriesResource) SetPreferences ¶ added in v0.6.0
func (r *StoriesResource) SetPreferences(ctx context.Context, prefs StoryPreferences) (*StoryActionResult, error)
SetPreferences sets your default story audience preference.
func (*StoriesResource) UploadMedia ¶ added in v0.6.0
func (r *StoriesResource) UploadMedia(ctx context.Context, file FileInput) (*StoryMediaUpload, error)
UploadMedia uploads story media (image/video) and returns its media id. Usually you don't call this directly — Create with Media does it for you.
func (*StoriesResource) View ¶ added in v0.6.0
func (r *StoriesResource) View(ctx context.Context, storyID string) (*StoryActionResult, error)
View marks a story as viewed.
type Story ¶ added in v0.6.0
type Story struct {
ID string `json:"id"`
UserID string `json:"user_id"`
MediaID string `json:"media_id"`
MediaType string `json:"media_type"`
Caption string `json:"caption"`
ExpiresAt string `json:"expires_at"` // ISO 8601
ViewCount int `json:"view_count"`
CreatedAt string `json:"created_at"` // ISO 8601
Audience string `json:"audience"`
AudienceUserIDs []string `json:"audience_user_ids,omitempty"`
// Enriched on read.
AuthorName string `json:"author_name,omitempty"`
AuthorAvatar *string `json:"author_avatar,omitempty"`
ViewedByMe bool `json:"viewed_by_me,omitempty"`
MediaURL *string `json:"media_url,omitempty"`
}
Story is an ephemeral story (24 h).
type StoryActionResult ¶ added in v0.6.0
type StoryActionResult struct {
Done bool `json:"done"`
}
StoryActionResult is returned by actions without a body (delete, view, set preferences).
type StoryMediaUpload ¶ added in v0.6.0
type StoryMediaUpload struct {
MediaID string `json:"media_id"`
URL string `json:"url"`
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
ThumbnailURL string `json:"thumbnail_url,omitempty"`
MediumURL string `json:"medium_url,omitempty"`
}
StoryMediaUpload is returned when uploading story media (image/video).
type StoryPreferences ¶ added in v0.6.0
type StoryPreferences struct {
Audience string `json:"audience"`
AudienceUserIDs []string `json:"audience_user_ids"`
}
StoryPreferences holds the default audience preference for new stories.
type StoryView ¶ added in v0.6.0
type StoryView struct {
StoryID string `json:"story_id"`
ViewerID string `json:"viewer_id"`
ViewedAt string `json:"viewed_at"` // ISO 8601
ViewerName string `json:"viewer_name,omitempty"`
ViewerAvatar *string `json:"viewer_avatar,omitempty"`
}
StoryView is a single view of a story (enriched with viewer name/avatar).
type TypingResult ¶
type TypingResult struct {
Typing bool `json:"typing"`
}
TypingResult is returned by the sendTyping endpoint.
type UpdateCommunityParams ¶ added in v0.3.0
type UpdateCommunityParams struct {
CommunityID int64 `json:"community_id"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
AvatarURL *string `json:"avatar_url,omitempty"`
AnnouncementChannelID *int64 `json:"announcement_channel_id,omitempty"`
RequiresApproval *bool `json:"requires_approval,omitempty"`
}
UpdateCommunityParams updates only the non-nil fields.
type User ¶
type User struct {
// Messages provides methods to send and manage messages.
Messages *MessagesResource
// Chats provides methods to list and iterate over chats.
Chats *ChatsResource
// Webhooks provides methods to manage webhooks.
Webhooks *WebhooksResource
// Profile provides access to your own profile.
Profile *UserProfileResource
// Communities provides methods to manage communities (members, roles, invites, requests).
Communities *CommunitiesResource
// Stories provides methods to create and manage your stories (ephemeral, 24 h).
Stories *StoriesResource
// contains filtered or unexported fields
}
User is the Kappela personal automation client. Authenticate with a personal API key (sk_...) to send messages and receive events as yourself.
Example:
me := kappelas.NewUser("sk_...")
me.OnMessage(func(msg *kappelas.Message) {
fmt.Println("New message:", msg.Text)
})
me.Start()
select {}
func NewUser ¶
func NewUser(apiKey string, opts ...UserOption) *User
NewUser creates a User authenticated with the given personal API key.
func (*User) GetAutomationStatus ¶ added in v0.4.0
func (u *User) GetAutomationStatus(ctx context.Context) (*AutomationStatus, error)
GetAutomationStatus reports whether this account's personal automations are paused.
func (*User) HandleWebhook ¶
HandleWebhook processes a webhook payload sent by Kappela to your server.
Example (net/http):
http.HandleFunc("/kappela-webhook", func(w http.ResponseWriter, r *http.Request) {
body, _ := io.ReadAll(r.Body)
me.HandleWebhook(body)
w.WriteHeader(http.StatusOK)
})
func (*User) OnCallbackQuery ¶
func (u *User) OnCallbackQuery(h func(*CallbackQuery))
OnCallbackQuery registers a handler called when a user clicks an inline button.
func (*User) OnConnected ¶
func (u *User) OnConnected(h func())
OnConnected registers a handler called when the WebSocket connects (or reconnects).
func (*User) OnDisconnected ¶
OnDisconnected registers a handler called when the WebSocket disconnects.
func (*User) PauseAutomationInChat ¶ added in v0.5.0
func (u *User) PauseAutomationInChat(ctx context.Context, chatID int64) (*ChatAutomationResult, error)
PauseAutomationInChat pauses your personal automations in ONE conversation only.
Use this to take over a single chat (e.g. you start replying to X yourself): your AI stops receiving messages from that conversation while it keeps handling all your other chats. Unlike PauseAutomations, this is scoped to a single conversation.
func (*User) PauseAutomations ¶ added in v0.4.0
func (u *User) PauseAutomations(ctx context.Context) (*AutomationStatus, error)
PauseAutomations pauses this account's personal automations.
While paused, the account stops receiving incoming messages over /v1/me (so an AI auto-responder is never triggered) and any send call is rejected with AUTOMATIONS_PAUSED. Useful when the human owner takes over the chat.
func (*User) Reply ¶ added in v0.6.0
func (u *User) Reply(ctx context.Context, event any, text string, opts ...SendMessageParams) (*SendResult, error)
Reply sends a text reply to a Message or CallbackQuery event.
- When called with a *Message — sets ChatID and ReplyToID automatically (shows a quote banner).
- When called with a *CallbackQuery — sets ChatID only (callback queries have no message ID).
Pass an optional SendMessageParams to attach a keyboard or set other options. ChatID, ReplyToID, and Text in opts are overwritten automatically.
Example:
me.OnMessage(func(msg *kappelas.Message) {
me.Reply(context.Background(), msg, "Got it! 👋")
})
func (*User) ResumeAutomationInChat ¶ added in v0.5.0
func (u *User) ResumeAutomationInChat(ctx context.Context, chatID int64) (*ChatAutomationResult, error)
ResumeAutomationInChat resumes your personal automations in a conversation.
func (*User) ResumeAutomations ¶ added in v0.4.0
func (u *User) ResumeAutomations(ctx context.Context) (*AutomationStatus, error)
ResumeAutomations resumes this account's personal automations after PauseAutomations.
type UserOption ¶
type UserOption func(*userConfig)
UserOption configures a User.
func WithUserBaseURL ¶
func WithUserBaseURL(u string) UserOption
WithUserBaseURL overrides the API base URL for a User client.
func WithUserMaxRetries ¶
func WithUserMaxRetries(n int) UserOption
WithUserMaxRetries sets the maximum number of HTTP retry attempts for a User client.
func WithUserTimeout ¶
func WithUserTimeout(d time.Duration) UserOption
WithUserTimeout sets the HTTP request timeout for a User client.
func WithUserWSMaxRetries ¶
func WithUserWSMaxRetries(n int) UserOption
WithUserWSMaxRetries sets the maximum WebSocket reconnect attempts for a User client.
type UserProfile ¶
type UserProfile struct {
ID string `json:"id"`
Username string `json:"username"`
Nom string `json:"nom"`
IsBot bool `json:"is_bot"`
IsPremium bool `json:"is_premium"`
AvatarURL *string `json:"avatar_url"`
AllowGroupAdd PrivacySetting `json:"allow_group_add"`
AllowCalls PrivacySetting `json:"allow_calls"`
}
UserProfile is the profile returned for a personal account.
type UserProfileResource ¶
type UserProfileResource struct {
// contains filtered or unexported fields
}
UserProfileResource provides access to the user's own profile.
func (*UserProfileResource) Get ¶
func (r *UserProfileResource) Get(ctx context.Context) (*UserProfile, error)
Get returns your own profile.
type WebhookDeleteResult ¶
type WebhookDeleteResult struct {
Active bool `json:"active"`
}
WebhookDeleteResult is returned after removing a webhook.
type WebhookInfo ¶
type WebhookInfo struct {
Active bool `json:"active"`
URL *string `json:"url"`
CreatedAt *int64 `json:"created_at"`
}
WebhookInfo describes the current webhook configuration.
type WebhookSetResult ¶
WebhookSetResult is returned after registering a webhook.
type WebhooksResource ¶
type WebhooksResource struct {
// contains filtered or unexported fields
}
WebhooksResource provides methods to manage webhooks.
func (*WebhooksResource) Delete ¶
func (r *WebhooksResource) Delete(ctx context.Context) (*WebhookDeleteResult, error)
Delete removes the webhook. Events will no longer be delivered via HTTP POST.
func (*WebhooksResource) GetInfo ¶
func (r *WebhooksResource) GetInfo(ctx context.Context) (*WebhookInfo, error)
GetInfo returns the current webhook status and URL.
func (*WebhooksResource) Set ¶
func (r *WebhooksResource) Set(ctx context.Context, params SetWebhookParams) (*WebhookSetResult, error)
Set registers a webhook URL. Use this for production deployments.