Documentation
¶
Index ¶
- type AddChatMemberParams
- type AddChatMemberResult
- type BanChatMemberParams
- type BanChatMemberResult
- type Bot
- func (b *Bot) Connected() bool
- 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) Reply(ctx context.Context, event any, text string, opts ...SendMessageParams) (*SendResult, error)
- func (b *Bot) Start()
- func (b *Bot) Stop()
- type BotGroupEntry
- type BotOption
- type BotProfile
- type BotProfileResource
- type CallbackQuery
- type CarouselCard
- type Chat
- 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 CreateChatInviteLinkParams
- 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 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 ReplyKeyboard
- type ReplyKeyboardButton
- type ReplySnapshot
- type RevokeChatInviteLinkParams
- type RevokeChatInviteLinkResult
- type ScrollKeyboard
- type ScrollKeyboardButton
- type SendCarouselParams
- type SendCarouselResult
- type SendMediaParams
- type SendMediaResult
- type SendMessageParams
- type SendResult
- type SendTypingParams
- type SetWebhookParams
- type TypingResult
- type User
- func (u *User) Connected() bool
- 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) Start()
- func (u *User) Stop()
- type UserOption
- type UserProfile
- type UserProfileResource
- type WebhookDeleteResult
- type WebhookInfo
- type WebhookSetResult
- type WebhooksResource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddChatMemberParams ¶ added in v0.1.2
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.1.2
type AddChatMemberResult struct {
Description string `json:"description"`
}
AddChatMemberResult is returned after successfully adding a user.
type BanChatMemberParams ¶ added in v0.1.2
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.1.2
type BanChatMemberResult struct {
Description string `json:"description"`
}
BanChatMemberResult is returned after successfully removing a user.
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
// 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) 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) Reply ¶ added in v0.1.2
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)
})
type BotGroupEntry ¶ added in v0.1.2
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 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.1.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 ChatInviteLink ¶ added in v0.1.2
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.1.2
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.1.2
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.1.2
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.1.2
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.1.2
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.1.2
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.1.2
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.1.2
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.1.2
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.1.2
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.1.2
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.1.2
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 CreateChatInviteLinkParams ¶ added in v0.1.2
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 DeleteMessageParams ¶
type DeleteMessageParams struct {
ChatID int64 `json:"chat_id"`
MessageID int64 `json:"message_id"`
}
DeleteMessageParams holds the parameters for deleting a message.
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"`
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.
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.1.2
type GetChatAdministratorsParams struct {
ChatID int64 `json:"chat_id"`
}
GetChatAdministratorsParams holds the parameters for fetching chat admins.
type GetChatAdministratorsResult ¶ added in v0.1.2
type GetChatAdministratorsResult struct {
Admins []ChatMemberInfo `json:"admins"`
}
GetChatAdministratorsResult contains all admins of a group or channel.
type GetChatInviteLinksParams ¶ added in v0.1.2
type GetChatInviteLinksParams struct {
ChatID int64 `json:"chat_id"`
}
GetChatInviteLinksParams holds the parameters for listing invite links.
type GetChatInviteLinksResult ¶ added in v0.1.2
type GetChatInviteLinksResult struct {
InviteLinks []ChatInviteLink `json:"invite_links"`
}
GetChatInviteLinksResult contains all active invite links for a group or channel.
type GetChatMemberParams ¶ added in v0.1.2
GetChatMemberParams holds the parameters for looking up a single member.
type GetChatsParams ¶
GetChatsParams holds the parameters for listing chats.
type GetMyGroupsResult ¶ added in v0.1.2
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.1.2
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.1.2
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.1.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.1.2
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.1.2
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.1.2
type PromoteChatMemberResult struct {
UserID string `json:"user_id"`
Role ParticipantRole `json:"role"`
}
PromoteChatMemberResult is returned after a role change.
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.1.2
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.1.2
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.1.2
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.1.2
RevokeChatInviteLinkResult is returned after revoking a link.
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.1.2
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"`
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.
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
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.
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"`
Text string `json:"text"`
// ReplyMarkup accepts InlineKeyboard, ReplyKeyboard, or ScrollKeyboard.
ReplyMarkup any `json:"reply_markup,omitempty"`
ReplyToID *int64 `json:"reply_to_id,omitempty"`
DeletePrevious bool `json:"delete_previous,omitempty"`
}
SendMessageParams holds the parameters for sending a text message.
type SendResult ¶
SendResult is returned after sending a text message.
type SendTypingParams ¶
type SendTypingParams struct {
ChatID int64 `json:"chat_id"`
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.
type SetWebhookParams ¶
SetWebhookParams holds the parameters for registering a webhook.
type TypingResult ¶
type TypingResult struct {
Typing bool `json:"typing"`
}
TypingResult is returned by the sendTyping endpoint.
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
// 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) 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.
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.