Other Bound Methods ​
Several other types in the mtgo ecosystem have bound convenience methods.
ChatJoinRequest ​
A *types.ChatJoinRequest is dispatched when a user requests to join a chat. It has approve/decline methods.
Approve ​
Approve the join request.
func (r *ChatJoinRequest) Approve() errorExample:
dispatcher.OnChatJoinRequest(func(ctx context.Context, req *types.ChatJoinRequest) error {
return req.Approve()
})Decline ​
Decline the join request.
func (r *ChatJoinRequest) Decline() errorPreCheckoutQuery ​
A *types.PreCheckoutQuery is sent when a user confirms a payment but before the charge is finalized. You must respond within 10 seconds.
Answer ​
Approve or reject the pre-checkout query.
func (q *PreCheckoutQuery) Answer(ok bool, errorMsg string) errorParameters:
| Parameter | Type | Description |
|---|---|---|
| ok | bool | true to approve, false to reject |
| errorMsg | string | Error message to show the user (when ok is false) |
Example:
dispatcher.OnPreCheckoutQuery(func(ctx context.Context, q *types.PreCheckoutQuery) error {
if validPayment(q) {
return q.Answer(true, "")
}
return q.Answer(false, "Payment expired")
})ShippingQuery ​
A *types.ShippingQuery is sent when a user selects a shipping address during checkout so you can return available shipping options.
Answer ​
Respond with shipping options or an error.
func (q *ShippingQuery) Answer(ok bool, errorMsg string) errorParameters:
| Parameter | Type | Description |
|---|---|---|
| ok | bool | true if shipping is available, false otherwise |
| errorMsg | string | Error message when ok is false |
Example:
dispatcher.OnShippingQuery(func(ctx context.Context, q *types.ShippingQuery) error {
if canShipTo(q.Address.CountryCode) {
return q.Answer(true, "")
}
return q.Answer(false, "We don't ship to your country")
})ActiveSession ​
A *types.ActiveSession represents an active session on the account (e.g. from client.GetAuthorizations()).
Reset ​
Terminate this session (log out the device).
func (s *ActiveSession) Reset() errorExample:
sessions, _ := client.GetAuthorizations(ctx)
for _, s := range sessions.Sessions {
if s.IP == "suspicious IP" {
s.Reset()
}
}Folder ​
A *types.Folder represents a chat folder (dialog filter). It has methods for managing folder membership and settings.
Delete ​
Delete this folder.
func (f *Folder) Delete() errorEdit ​
Edit the folder name and/or icon.
func (f *Folder) Edit(name string, icon string) errorParameters:
| Parameter | Type | Description |
|---|---|---|
| name | string | New folder name (empty to keep current) |
| icon | string | New folder icon emoji (empty to keep current) |
IncludeChat ​
Add a chat to this folder's included chats.
func (f *Folder) IncludeChat(chatID int64) errorExcludeChat ​
Add a chat to this folder's excluded chats.
func (f *Folder) ExcludeChat(chatID int64) errorUpdateColor ​
Update the folder color.
func (f *Folder) UpdateColor(color int32) errorPinChat ​
Pin a chat within this folder.
func (f *Folder) PinChat(chatID int64) errorRemoveChat ​
Remove a chat from this folder.
func (f *Folder) RemoveChat(chatID int64) errorExample:
folders, _ := client.GetChatFolders(ctx)
for _, folder := range folders {
if folder.Name == "Work" {
folder.IncludeChat(workGroupID)
folder.PinChat(importantChatID)
}
}