takeout

package
v0.139.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 7, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package takeout provides a wrapper for Telegram takeout sessions.

Takeout sessions allow exporting user data from Telegram. See https://core.telegram.org/api/takeout for more information.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, invoker tg.Invoker, cfg Config, f func(ctx context.Context, client *Client) error) error

Run initializes a takeout session and calls the provided function.

The session is automatically finished when the function returns. If the function returns nil, the session is marked as successful. Otherwise, the session is marked as failed.

Example
package main

import (
	"context"
	"fmt"

	"github.com/gotd/td/telegram/takeout"
	"github.com/gotd/td/tg"
)

func main() {
	// This example demonstrates how to use the takeout API wrapper.
	// In a real application, you would use a proper tg.Invoker.

	ctx := context.Background()
	var invoker tg.Invoker // obtained from telegram.Client

	// Configure what data to export
	cfg := takeout.Config{
		Contacts:          true,
		MessageUsers:      true,
		MessageChats:      true,
		MessageMegagroups: true,
		MessageChannels:   true,
		Files:             true,
		FileMaxSize:       512 * 1024 * 1024, // 512 MB
	}

	err := takeout.Run(ctx, invoker, cfg, func(ctx context.Context, client *takeout.Client) error {
		// All API calls made with client are wrapped with takeout session.
		// Use tg.NewClient(client) to get a full API client.
		api := tg.NewClient(client)

		// For example, get dialogs:
		dialogs, err := api.MessagesGetDialogs(ctx, &tg.MessagesGetDialogsRequest{
			Limit: 100,
		})
		if err != nil {
			return err
		}

		fmt.Printf("Got dialogs: %T\n", dialogs)
		return nil
	})
	if err != nil {
		// Handle error
		_ = err
	}
}

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client wraps tg.Invoker to use a takeout session.

func (*Client) ID

func (c *Client) ID() int64

ID returns takeout session ID.

func (*Client) Invoke

func (c *Client) Invoke(ctx context.Context, input bin.Encoder, output bin.Decoder) error

Invoke implements tg.Invoker.

func (*Client) Raw

func (c *Client) Raw() tg.Invoker

Raw returns underlying invoker.

type Config

type Config struct {
	// Contacts enables exporting contacts.
	Contacts bool
	// MessageUsers enables exporting messages from private chats.
	MessageUsers bool
	// MessageChats enables exporting messages from basic groups.
	MessageChats bool
	// MessageMegagroups enables exporting messages from supergroups.
	MessageMegagroups bool
	// MessageChannels enables exporting messages from channels.
	MessageChannels bool
	// Files enables exporting files.
	Files bool
	// FileMaxSize sets maximum file size to export.
	// Only used if Files is true.
	FileMaxSize int64
}

Config configures takeout session.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL