unpack

package
v0.0.0-...-f756a1e Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2023 License: MIT Imports: 3 Imported by: 1

Documentation

Overview

Package unpack contains some updates result unpacking helpers.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Message

func Message(u tg.UpdatesClass, err error) (*tg.Message, error)

Message tries to unpack sent message and returns it as Message.

Example
package main

import (
	"context"
	"fmt"
	"os"
	"os/signal"

	"github.com/voyager-hang/gotd-td/telegram"
	"github.com/voyager-hang/gotd-td/telegram/message"
	"github.com/voyager-hang/gotd-td/telegram/message/unpack"
	"github.com/voyager-hang/gotd-td/tg"
)

func unpackMessage(ctx context.Context) error {
	client, err := telegram.ClientFromEnvironment(telegram.Options{})
	if err != nil {
		return err
	}

	return client.Run(ctx, func(ctx context.Context) error {
		sender := message.NewSender(tg.NewClient(client))

		msg, err := unpack.Message(sender.Resolve("@durovschat").Dice(ctx))
		// Sends dice "🎲" to the @durovschat.
		if err != nil {
			return err
		}

		fmt.Println("Sent message ID:", msg.ID)

		return nil
	})
}

func main() {
	ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
	defer cancel()

	if err := unpackMessage(ctx); err != nil {
		_, _ = fmt.Fprintf(os.Stderr, "%+v\n", err)
		os.Exit(2)
	}
}
Output:

func MessageClass

func MessageClass(u tg.UpdatesClass, err error) (tg.MessageClass, error)

MessageClass tries to unpack sent message and returns it as MessageClass.

func MessageID

func MessageID(u tg.UpdatesClass, err error) (int, error)

MessageID tries to unpack sent message and returns message id.

Types

This section is empty.

Jump to

Keyboard shortcuts

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