message

package
v0.0.0-...-87e9d67 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package message contains some useful utilities for creating Telegram messages.

Code generated by mktyping, DO NOT EDIT.

Index

Examples

Constants

View Source
const (
	// DiceEmoticon is an emoticon to send dice sticker.
	DiceEmoticon = "🎲"
	// DartsEmoticon is an emoticon to send darts sticker.
	DartsEmoticon = "🎯"
	// BasketballEmoticon is an emoticon to send basketball sticker.
	BasketballEmoticon = "🏀"
	// FootballEmoticon is an emoticon to send football sticker.
	FootballEmoticon = "⚽"
	// CasinoEmoticon is an emoticon to send casino sticker.
	CasinoEmoticon = "🎰"
	// BowlingEmoticon is an emoticon to send bowling sticker.
	BowlingEmoticon = "🎳"
)
View Source
const (
	// DefaultVoiceMIME is a default voice MIME to use.
	DefaultVoiceMIME = "audio/ogg"

	// DefaultAudioMIME is a default audio MIME to use.
	DefaultAudioMIME = "audio/mp3"

	// DefaultVideoMIME is a default video MIME to use.
	DefaultVideoMIME = "video/mp4"

	// DefaultGifMIME is a default gif MIME to use.
	DefaultGifMIME = "image/gif"

	// DefaultStickerMIME is a default sticker MIME to use.
	DefaultStickerMIME = "image/webp"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AnswerableMessageUpdate

type AnswerableMessageUpdate interface {
	GetMessage() tg.MessageClass
}

AnswerableMessageUpdate represents update which can be used to answer.

type AudioDocumentBuilder

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

AudioDocumentBuilder is an Audio media option.

func Audio

func Audio(file tg.InputFileClass, caption ...StyledTextOption) *AudioDocumentBuilder

Audio adds audio attachment.

Example
package main

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

	"github.com/go-faster/errors"

	"bitbucket.org/hokego/hokego-td/telegram"
	"bitbucket.org/hokego/hokego-td/telegram/message"
	"bitbucket.org/hokego/hokego-td/telegram/uploader"
	"bitbucket.org/hokego/hokego-td/tg"
)

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

	return client.Run(ctx, func(ctx context.Context) error {
		raw := tg.NewClient(client)
		// Upload file.
		f, err := uploader.NewUploader(raw).FromPath(ctx, "vsyo idyot po planu.mp3")
		if err != nil {
			return errors.Wrap(err, "upload")
		}

		sender := message.NewSender(raw)
		r := sender.Resolve("@durovschat")

		// Sends audio to the @durovschat.
		if _, err := r.Audio(ctx, f); err != nil {
			return err
		}

		// Sends audio with title to the @durovschat.
		if _, err := r.Media(ctx, message.Audio(f).
			Performer("Yegor Letov").
			Title("Everything is going according to plan")); err != nil {
			return err
		}

		// Sends voice message to the @durovschat.
		if _, err := r.Voice(ctx, f); err != nil {
			return err
		}

		return nil
	})
}

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

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

func Voice

Voice adds voice attachment.

func (*AudioDocumentBuilder) Duration

func (u *AudioDocumentBuilder) Duration(duration time.Duration) *AudioDocumentBuilder

Duration sets duration of audio file.

func (*AudioDocumentBuilder) DurationSeconds

func (u *AudioDocumentBuilder) DurationSeconds(duration int) *AudioDocumentBuilder

DurationSeconds sets duration in seconds.

func (*AudioDocumentBuilder) Performer

func (u *AudioDocumentBuilder) Performer(performer string) *AudioDocumentBuilder

Performer sets performer.

func (*AudioDocumentBuilder) Title

Title sets name of song.

func (*AudioDocumentBuilder) Voice

Voice sets flag to mark this audio as voice message.

func (*AudioDocumentBuilder) Waveform

func (u *AudioDocumentBuilder) Waveform(waveform []byte) *AudioDocumentBuilder

Waveform sets waveform representation of the voice message.

type Builder

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

Builder is a message builder.

func (*Builder) Album

func (b *Builder) Album(ctx context.Context, media MultiMediaOption, album ...MultiMediaOption) (tg.UpdatesClass, error)

Album sends message with multiple media attachments.

func (*Builder) Audio

func (b *Builder) Audio(
	ctx context.Context,
	file tg.InputFileClass, caption ...StyledTextOption,
) (tg.UpdatesClass, error)

Audio sends audio file.

func (*Builder) Background

func (b *Builder) Background() *Builder

Background sets flag to send this message as background message.

func (*Builder) Basketball

func (b *Builder) Basketball(ctx context.Context) (tg.UpdatesClass, error)

Basketball sends a basketball animated sticker.

func (*Builder) Bowling

func (b *Builder) Bowling(ctx context.Context) (tg.UpdatesClass, error)

Bowling sends a bowling animated sticker.

func (*Builder) Casino

func (b *Builder) Casino(ctx context.Context) (tg.UpdatesClass, error)

Casino sends a casino animated sticker.

func (*Builder) Clear

func (b *Builder) Clear() *Builder

Clear sets flag to clear the draft field.

func (*Builder) ClearDraft

func (b *Builder) ClearDraft(ctx context.Context) error

ClearDraft clears draft. Also, you can use Clear() builder option with any other message send method.

See https://core.telegram.org/api/drafts#clearing-drafts.

func (*Builder) Darts

func (b *Builder) Darts(ctx context.Context) (tg.UpdatesClass, error)

Darts sends a darts animated sticker.

func (*Builder) Dice

func (b *Builder) Dice(ctx context.Context) (tg.UpdatesClass, error)

Dice sends a dice animated sticker.

func (*Builder) Document

func (b *Builder) Document(
	ctx context.Context, file FileLocation, caption ...StyledTextOption,
) (tg.UpdatesClass, error)

Document sends document.

func (*Builder) DocumentByHash

func (b *Builder) DocumentByHash(
	ctx context.Context, hash []byte, size int64, mime string,
	caption ...StyledTextOption,
) (tg.UpdatesClass, error)

DocumentByHash finds document by hash and sends as attachment.

func (*Builder) DocumentExternal

func (b *Builder) DocumentExternal(ctx context.Context, url string, caption ...StyledTextOption) (tg.UpdatesClass, error)

DocumentExternal sends document attachment that will be downloaded by the Telegram servers.

func (*Builder) Edit

func (b *Builder) Edit(id int) *EditMessageBuilder

Edit edits message by ID.

func (*Builder) File

func (b *Builder) File(ctx context.Context, file tg.InputFileClass, caption ...StyledTextOption) (tg.UpdatesClass, error)

File sends uploaded file as document and forces it to be used as plain file, not media.

func (*Builder) Football

func (b *Builder) Football(ctx context.Context) (tg.UpdatesClass, error)

Football sends a football animated sticker.

func (*Builder) ForwardIDs

func (b *Builder) ForwardIDs(from tg.InputPeerClass, id int, ids ...int) *ForwardBuilder

ForwardIDs creates builder to forward messages by ID.

func (*Builder) ForwardMessages

func (b *Builder) ForwardMessages(from tg.InputPeerClass, msg tg.MessageClass, m ...tg.MessageClass) *ForwardBuilder

ForwardMessages creates builder to forward messages.

func (*Builder) GIF

func (b *Builder) GIF(
	ctx context.Context,
	file tg.InputFileClass, caption ...StyledTextOption,
) (tg.UpdatesClass, error)

GIF sends gif.

func (*Builder) InlineResult

func (b *Builder) InlineResult(ctx context.Context, id string, queryID int64, hideVia bool) (tg.UpdatesClass, error)

InlineResult is a user method to send bot inline query result message.

func (*Builder) Markup

func (b *Builder) Markup(m tg.ReplyMarkupClass) *Builder

Markup sets reply markup for sending bot buttons.

NB: markup will not be used, if you send multiple media attachments.

func (*Builder) Media

func (b *Builder) Media(ctx context.Context, media MediaOption) (tg.UpdatesClass, error)

Media sends message with media attachment.

func (*Builder) NoForwards

func (b *Builder) NoForwards() *Builder

NoForwards whether that sent message cannot be forwarded.

See https://telegram.org/blog/protected-content-delete-by-date-and-more#protected-content-in-groups-and-channels.

func (*Builder) NoWebpage

func (b *Builder) NoWebpage() *Builder

NoWebpage sets flag to disable generation of the webpage preview.

func (*Builder) Photo

func (b *Builder) Photo(
	ctx context.Context,
	photo FileLocation, caption ...StyledTextOption,
) (tg.UpdatesClass, error)

Photo sends photo.

func (*Builder) PhotoExternal

func (b *Builder) PhotoExternal(
	ctx context.Context,
	url string, caption ...StyledTextOption,
) (tg.UpdatesClass, error)

PhotoExternal sends photo attachment which will be downloaded by the Telegram servers.

func (*Builder) Reply

func (b *Builder) Reply(id int) *Builder

Reply sets message ID to reply.

func (*Builder) ReplyMsg

func (b *Builder) ReplyMsg(msg tg.MessageClass) *Builder

ReplyMsg sets message to reply.

func (*Builder) RoundVideo

func (b *Builder) RoundVideo(
	ctx context.Context,
	file tg.InputFileClass, caption ...StyledTextOption,
) (tg.UpdatesClass, error)

RoundVideo sends round video.

func (*Builder) Row

func (b *Builder) Row(buttons ...tg.KeyboardButtonClass) *Builder

Row sets single row keyboard markup for sending bot buttons.

NB: markup will not be used, if you send multiple media attachments.

func (*Builder) SaveDraft

func (b *Builder) SaveDraft(ctx context.Context, msg string) error

SaveDraft saves given message as draft.

See https://core.telegram.org/api/drafts#saving-drafts.

Example
package main

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

	"github.com/go-faster/errors"

	"bitbucket.org/hokego/hokego-td/telegram"
	"bitbucket.org/hokego/hokego-td/telegram/message"
	"bitbucket.org/hokego/hokego-td/telegram/message/styling"
	"bitbucket.org/hokego/hokego-td/tg"
)

func saveDraft(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))
		r := sender.Resolve("@durov")

		// Save draft message.
		if err := r.SaveDraft(ctx, "Hi!"); err != nil {
			return errors.Wrap(err, "draft")
		}

		// Save styled draft message.
		if err := r.SaveStyledDraft(ctx, styling.Bold("Hi!")); err != nil {
			return errors.Wrap(err, "draft")
		}

		// Clear draft for resolved @durov peer.
		if err := r.ClearDraft(ctx); err != nil {
			return errors.Wrap(err, "draft")
		}

		return nil
	})
}

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

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

func (*Builder) SaveStyledDraft

func (b *Builder) SaveStyledDraft(ctx context.Context, texts ...StyledTextOption) error

SaveStyledDraft saves given styled message as draft.

See https://core.telegram.org/api/drafts#saving-drafts.

func (*Builder) Schedule

func (b *Builder) Schedule(date time.Time) *Builder

Schedule sets scheduled message date for scheduled messages.

func (*Builder) ScheduleTS

func (b *Builder) ScheduleTS(date int) *Builder

ScheduleTS sets scheduled message timestamp for scheduled messages.

func (*Builder) Silent

func (b *Builder) Silent() *Builder

Silent sets flag to send this message silently (no notifications for the receivers).

func (*Builder) StyledText

func (b *Builder) StyledText(ctx context.Context, texts ...StyledTextOption) (tg.UpdatesClass, error)

StyledText sends styled text message.

Example
package main

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

	"bitbucket.org/hokego/hokego-td/telegram"
	"bitbucket.org/hokego/hokego-td/telegram/message"
	"bitbucket.org/hokego/hokego-td/telegram/message/styling"
	"bitbucket.org/hokego/hokego-td/tg"
)

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

	// This example creates a big message with different style lines
	// and sends to your Saved Messages folder.
	return client.Run(ctx, func(ctx context.Context) error {
		formats := []message.StyledTextOption{
			styling.Plain("plaintext"), styling.Plain("\n\n"),
			styling.Mention("@durov"), styling.Plain("\n\n"),
			styling.Hashtag("#hashtag"), styling.Plain("\n\n"),
			styling.BotCommand("/command"), styling.Plain("\n\n"),
			styling.URL("https://google.org"), styling.Plain("\n\n"),
			styling.Email("example@example.org"), styling.Plain("\n\n"),
			styling.Bold("bold"), styling.Plain("\n\n"),
			styling.Italic("italic"), styling.Plain("\n\n"),
			styling.Underline("underline"), styling.Plain("\n\n"),
			styling.Strike("strike"), styling.Plain("\n\n"),
			styling.Code("fmt.Println(`Hello, World!`)"), styling.Plain("\n\n"),
			styling.Pre("fmt.Println(`Hello, World!`)", "Go"), styling.Plain("\n\n"),
			styling.TextURL("clickme", "https://google.com"), styling.Plain("\n\n"),
			styling.Phone("+71234567891"), styling.Plain("\n\n"),
			styling.Cashtag("$CASHTAG"), styling.Plain("\n\n"),
			styling.Blockquote("blockquote"), styling.Plain("\n\n"),
			styling.BankCard("5550111111111111"), styling.Plain("\n\n"),
		}

		_, err := message.NewSender(tg.NewClient(client)).
			Self().StyledText(ctx, formats...)
		return err
	})
}

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

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

func (*Builder) Text

func (b *Builder) Text(ctx context.Context, msg string) (tg.UpdatesClass, error)

Text sends text message.

Example
package main

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

	"bitbucket.org/hokego/hokego-td/telegram"
	"bitbucket.org/hokego/hokego-td/telegram/message"
	"bitbucket.org/hokego/hokego-td/telegram/message/styling"
)

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

	return client.Run(ctx, func(ctx context.Context) error {
		s := message.NewSender(client.API())

		// Sends message to your Saved Message folder.
		if _, err := s.Self().Text(ctx, "Hi!"); err != nil {
			return err
		}

		// Resolves @my_channel and gets tg.InputPeerClass.
		p, err := s.Resolve("my_channel").AsInputPeer(ctx)
		if err != nil {
			return err
		}

		// Replies to message ID = 1 in @gotd_en as @my_channel with spoiler message "spoiler".
		if _, err := s.Resolve("gotd_en").
			SendAs(p).Reply(1).
			StyledText(ctx, styling.Spoiler("spoiler")); err != nil {
			return err
		}

		// Sends message to channel
		return err
	})
}

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

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

func (*Builder) Textf

func (b *Builder) Textf(ctx context.Context, format string, args ...interface{}) (tg.UpdatesClass, error)

Textf formats and sends text message.

func (*Builder) Upload

func (b *Builder) Upload(upd UploadOption) *UploadBuilder

Upload creates new UploadBuilder to upload and send attachments. Given option will be called only once, even if you call upload functions.

func (*Builder) UploadMedia

func (b *Builder) UploadMedia(ctx context.Context, media MediaOption) (tg.MessageMediaClass, error)

UploadMedia uses messages.uploadMedia to upload a file and associate it to a chat (without actually sending it to the chat).

See https://core.telegram.org/method/messages.uploadMedia.

func (*Builder) UploadedPhoto

func (b *Builder) UploadedPhoto(
	ctx context.Context,
	file tg.InputFileClass, caption ...StyledTextOption,
) (tg.UpdatesClass, error)

UploadedPhoto sends uploaded file as photo.

func (*Builder) UploadedSticker

func (b *Builder) UploadedSticker(
	ctx context.Context,
	file tg.InputFileClass, caption ...StyledTextOption,
) (tg.UpdatesClass, error)

UploadedSticker sends uploaded file as sticker.

func (*Builder) Video

func (b *Builder) Video(
	ctx context.Context,
	file tg.InputFileClass, caption ...StyledTextOption,
) (tg.UpdatesClass, error)

Video sends video.

func (*Builder) Voice

func (b *Builder) Voice(ctx context.Context, file tg.InputFileClass) (tg.UpdatesClass, error)

Voice sends voice message.

type DeleteBuilder

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

DeleteBuilder is an intermediate builder to delete messages. Unlike RevokeBuilder will keep messages for other users.

func (*DeleteBuilder) Messages

func (b *DeleteBuilder) Messages(ctx context.Context, ids ...int) (*tg.MessagesAffectedMessages, error)

Messages deletes messages by given IDs, but keeps it for other users.

NB: Telegram counts message IDs globally for private chats (but not for channels). This method does not check that all given message IDs from one chat.

type DocumentBuilder

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

DocumentBuilder is a Document media option.

func Document

func Document(doc FileLocation, caption ...StyledTextOption) *DocumentBuilder

Document adds document attachment.

func (*DocumentBuilder) Query

func (u *DocumentBuilder) Query(query string) *DocumentBuilder

Query sets query field of InputMediaDocument.

func (*DocumentBuilder) TTL

TTL sets time to live of self-destructing document.

func (*DocumentBuilder) TTLSeconds

func (u *DocumentBuilder) TTLSeconds(ttl int) *DocumentBuilder

TTLSeconds sets time to live in seconds of self-destructing document.

type DocumentExternalBuilder

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

DocumentExternalBuilder is a DocumentExternal media option.

func DocumentExternal

func DocumentExternal(url string, caption ...StyledTextOption) *DocumentExternalBuilder

DocumentExternal adds document attachment that will be downloaded by the Telegram servers.

func (*DocumentExternalBuilder) TTL

TTL sets time to live of self-destructing document.

func (*DocumentExternalBuilder) TTLSeconds

TTLSeconds sets time to live in seconds of self-destructing document.

type EditMessageBuilder

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

EditMessageBuilder creates edit message builder.

func (*EditMessageBuilder) Media

Media edits message using given media and text.

func (*EditMessageBuilder) StyledText

func (b *EditMessageBuilder) StyledText(ctx context.Context, texts ...StyledTextOption) (tg.UpdatesClass, error)

StyledText edits message using given message.

func (*EditMessageBuilder) Text

Text edits message.

func (*EditMessageBuilder) Textf

func (b *EditMessageBuilder) Textf(ctx context.Context, format string, args ...interface{}) (tg.UpdatesClass, error)

Textf formats and edits message .

type FileLocation

type FileLocation interface {
	GetID() (value int64)
	GetAccessHash() (value int64)
	GetFileReference() (value []byte)
}

FileLocation is an abstraction of Telegram file location.

type FilePromise

type FilePromise = func(ctx context.Context, b Uploader) (tg.InputFileClass, error)

FilePromise is a upload file promise.

type ForwardBuilder

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

ForwardBuilder is a forward request builder.

func (*ForwardBuilder) Send

Send sends forwarded messages.

func (*ForwardBuilder) WithMyScore

func (b *ForwardBuilder) WithMyScore() *ForwardBuilder

WithMyScore sets flag to include your score in the forwarded game.

type InlineUpdate

type InlineUpdate interface {
	GetQueryID() int64
}

InlineUpdate is an abstraction for

type MediaOption

type MediaOption interface {
	// contains filtered or unexported methods
}

MediaOption is an option for sending media attachments.

func Basketball

func Basketball() MediaOption

Basketball adds a basketball animated sticker.

func Bowling

func Bowling() MediaOption

Bowling adds a bowling animated sticker.

func Casino

func Casino() MediaOption

Casino adds a casino animated sticker.

func Contact

func Contact(contact tg.InputMediaContact, caption ...StyledTextOption) MediaOption

Contact adds contact attachment.

func Darts

func Darts() MediaOption

Darts adds a darts animated sticker.

func Dice

func Dice() MediaOption

Dice adds a dice animated sticker.

func Football

func Football() MediaOption

Football adds a football animated sticker.

func Game

func Game(id tg.InputGameClass, caption ...StyledTextOption) MediaOption

Game adds a game attachment.

func GeoPoint

func GeoPoint(lat, long float64, accuracy int, caption ...StyledTextOption) MediaOption

GeoPoint adds geo point attachment. NB: parameter accuracy may be zero and will not be used.

func Media

func Media(media tg.InputMediaClass, caption ...StyledTextOption) MediaOption

Media adds given media attachment to message.

func MediaDice

func MediaDice(emoticon string) MediaOption

MediaDice adds a dice-based animated sticker.

Example
package main

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

	"bitbucket.org/hokego/hokego-td/telegram"
	"bitbucket.org/hokego/hokego-td/telegram/message"
	"bitbucket.org/hokego/hokego-td/tg"
)

func sendDice(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))

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

		// Sends darts "🎯" to the @durovschat.
		if _, err := sender.Resolve("https://t.me/durovschat").Darts(ctx); err != nil {
			return err
		}

		return nil
	})
}

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

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

type MultiMediaOption

type MultiMediaOption interface {
	MediaOption
	// contains filtered or unexported methods
}

MultiMediaOption is an option for sending albums.

func ForceMulti

func ForceMulti(opt MediaOption) MultiMediaOption

ForceMulti converts MediaOption to MultiMediaOption. It can produce unexpected RPC errors. Use carefully.

type PeerUpdate

type PeerUpdate interface {
	GetPeer() tg.PeerClass
}

PeerUpdate represents update which can be used to answer.

type PhotoBuilder

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

PhotoBuilder is a Photo media option.

func Photo

func Photo(photo FileLocation, caption ...StyledTextOption) *PhotoBuilder

Photo adds photo attachment.

func (*PhotoBuilder) TTL

func (u *PhotoBuilder) TTL(ttl time.Duration) *PhotoBuilder

TTL sets time to live of self-destructing photo.

func (*PhotoBuilder) TTLSeconds

func (u *PhotoBuilder) TTLSeconds(ttl int) *PhotoBuilder

TTLSeconds sets time to live in seconds of self-destructing photo.

type PhotoExternalBuilder

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

PhotoExternalBuilder is a PhotoExternal media option.

func PhotoExternal

func PhotoExternal(url string, caption ...StyledTextOption) *PhotoExternalBuilder

PhotoExternal adds photo attachment which will be downloaded by the Telegram servers.

func (*PhotoExternalBuilder) TTL

TTL sets time to live of self-destructing document.

func (*PhotoExternalBuilder) TTLSeconds

func (u *PhotoExternalBuilder) TTLSeconds(ttl int) *PhotoExternalBuilder

TTLSeconds sets time to live in seconds of self-destructing document.

type PollAnswerOption

type PollAnswerOption func(p *pollAnswerBuilder)

PollAnswerOption is an option to create poll answer.

func CorrectPollAnswer

func CorrectPollAnswer(text string) PollAnswerOption

CorrectPollAnswer creates new correct poll answer option.

func PollAnswer

func PollAnswer(text string) PollAnswerOption

PollAnswer creates new plain poll answer option.

func RawPollAnswer

func RawPollAnswer(poll tg.PollAnswer) PollAnswerOption

RawPollAnswer creates new raw poll answer option.

type PollBuilder

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

PollBuilder is a Poll media option.

func Poll

func Poll(question string, a, b PollAnswerOption, answers ...PollAnswerOption) *PollBuilder

Poll adds poll attachment.

func (*PollBuilder) Close

func (p *PollBuilder) Close() *PollBuilder

Close sets flag that the poll is closed and doesn't accept any more answers.

func (*PollBuilder) CloseDate

func (p *PollBuilder) CloseDate(d time.Time) *PollBuilder

CloseDate sets point in time (Unix timestamp) when the poll will be automatically closed. Must be at least 5 and no more than 600 seconds in the future.

func (*PollBuilder) CloseDateTS

func (p *PollBuilder) CloseDateTS(ts int) *PollBuilder

CloseDateTS sets point in time (Unix timestamp) when the poll will be automatically closed. Must be at least 5 and no more than 600 seconds in the future.

func (*PollBuilder) ClosePeriod

func (p *PollBuilder) ClosePeriod(d time.Duration) *PollBuilder

ClosePeriod sets amount of time in seconds the poll will be active after creation, 5-600 seconds.

func (*PollBuilder) ClosePeriodSeconds

func (p *PollBuilder) ClosePeriodSeconds(s int) *PollBuilder

ClosePeriodSeconds sets amount of time in seconds the poll will be active after creation, 5-600.

func (*PollBuilder) Explanation

func (p *PollBuilder) Explanation(msg string) *PollBuilder

Explanation sets explanation message.

func (*PollBuilder) MultipleChoice

func (p *PollBuilder) MultipleChoice(multipleChoice bool) *PollBuilder

MultipleChoice sets flag that multiple options can be chosen as answer.

func (*PollBuilder) PollID

func (p *PollBuilder) PollID() int64

PollID return poll ID. If poll was not sent, will be zero. It useful to close polls.

func (*PollBuilder) PublicVoters

func (p *PollBuilder) PublicVoters(publicVoters bool) *PollBuilder

PublicVoters sets flag that votes are publicly visible to all users (non-anonymous poll).

func (*PollBuilder) StyledExplanation

func (p *PollBuilder) StyledExplanation(texts ...StyledTextOption) *PollBuilder

StyledExplanation sets styled explanation message.

type ReportBuilder

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

ReportBuilder is a reporting messages helper.

func (*ReportBuilder) ChildAbuse

func (b *ReportBuilder) ChildAbuse(ctx context.Context) (bool, error)

ChildAbuse sends report for child abuse.

func (*ReportBuilder) Copyright

func (b *ReportBuilder) Copyright(ctx context.Context) (bool, error)

Copyright sends report for copyrighted content.

func (*ReportBuilder) Fake

func (b *ReportBuilder) Fake(ctx context.Context) (bool, error)

Fake sends report for fake.

func (*ReportBuilder) GeoIrrelevant

func (b *ReportBuilder) GeoIrrelevant(ctx context.Context) (bool, error)

GeoIrrelevant sends report for irrelevant geogroup.

func (*ReportBuilder) Message

func (b *ReportBuilder) Message(msg string) *ReportBuilder

Message sets additional comment for report.

func (*ReportBuilder) Other

func (b *ReportBuilder) Other(ctx context.Context) (bool, error)

Other sends report for other.

func (*ReportBuilder) Pornography

func (b *ReportBuilder) Pornography(ctx context.Context) (bool, error)

Pornography sends report for pornography.

func (*ReportBuilder) Spam

func (b *ReportBuilder) Spam(ctx context.Context) (bool, error)

Spam sends report for spam.

func (*ReportBuilder) Violence

func (b *ReportBuilder) Violence(ctx context.Context) (bool, error)

Violence sends report for violence.

type RequestBuilder

type RequestBuilder struct {
	Builder
}

RequestBuilder is an intermediate builder to make different RPC calls using Sender.

func (*RequestBuilder) AsInputChannel

func (b *RequestBuilder) AsInputChannel(ctx context.Context) (*tg.InputChannel, error)

AsInputChannel returns resolve result as InputChannel.

func (*RequestBuilder) AsInputChannelClass

func (b *RequestBuilder) AsInputChannelClass(ctx context.Context) (tg.InputChannelClass, error)

AsInputChannelClass returns resolve result as tg.NotEmptyInputChannel.

func (*RequestBuilder) AsInputPeer

func (b *RequestBuilder) AsInputPeer(ctx context.Context) (tg.InputPeerClass, error)

AsInputPeer returns resolve result as InputPeerClass.

func (*RequestBuilder) AsInputUser

func (b *RequestBuilder) AsInputUser(ctx context.Context) (*tg.InputUser, error)

AsInputUser returns resolve result as InputUser.

func (*RequestBuilder) AsInputUserClass

func (b *RequestBuilder) AsInputUserClass(ctx context.Context) (tg.InputUserClass, error)

AsInputUserClass returns resolve result as InputUserClass.

func (*RequestBuilder) CloneBuilder

func (b *RequestBuilder) CloneBuilder() *Builder

CloneBuilder returns copy of message Builder inside RequestBuilder.

func (*RequestBuilder) Join

Join joins resolved channel. NB: if resolved peer is not a channel, error will be returned.

func (*RequestBuilder) Leave

Leave leaves resolved peer.

NB: if resolved peer is not a channel or chat, or chat is deactivated, empty *tg.Updates will be returned.

func (*RequestBuilder) PeerSettings

func (b *RequestBuilder) PeerSettings(ctx context.Context) (*tg.PeerSettings, error)

PeerSettings returns peer settings.

func (*RequestBuilder) PollVote

func (b *RequestBuilder) PollVote(
	ctx context.Context, msgID int,
	answer []byte, answers ...[]byte,
) (tg.UpdatesClass, error)

PollVote votes in a poll.

func (*RequestBuilder) Reaction

func (b *RequestBuilder) Reaction(ctx context.Context, msgID int, reaction ...tg.ReactionClass) (tg.UpdatesClass, error)

Reaction sends reaction for given message.

func (*RequestBuilder) Report

func (b *RequestBuilder) Report(id int, ids ...int) *ReportBuilder

Report reports messages in a chat for violation of Telegram's Terms of Service.

func (*RequestBuilder) ReportSpam

func (b *RequestBuilder) ReportSpam(ctx context.Context) (bool, error)

ReportSpam reports peer for spam. NB: You should check that the peer settings of the chat allow us to do that.

func (*RequestBuilder) Revoke

func (b *RequestBuilder) Revoke() *RevokeBuilder

Revoke creates new RevokeBuilder.

func (*RequestBuilder) Scheduled

func (b *RequestBuilder) Scheduled() *ScheduledManager

Scheduled creates new ScheduledManager using resolved peer.

func (*RequestBuilder) ScreenshotNotify

func (b *RequestBuilder) ScreenshotNotify(ctx context.Context, msgID int) (tg.UpdatesClass, error)

ScreenshotNotify sends notification about screenshot. Parameter msgID is an ID of message that was screenshotted, can be 0.

func (*RequestBuilder) TypingAction

func (b *RequestBuilder) TypingAction() *TypingActionBuilder

TypingAction creates TypingActionBuilder.

type RevokeBuilder

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

RevokeBuilder is an intermediate builder to delete messages. Unlike DeleteBuilder will not keep messages for other users.

func (*RevokeBuilder) Messages

func (b *RevokeBuilder) Messages(ctx context.Context, ids ...int) (*tg.MessagesAffectedMessages, error)

Messages deletes messages by given IDs.

NB: Telegram counts message IDs globally for private chats (but not for channels). This method does not check that all given message IDs from one chat.

type ScheduledManager

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

ScheduledManager is a scheduled messages manager.

func (*ScheduledManager) Delete

func (m *ScheduledManager) Delete(ctx context.Context, id int, ids ...int) (tg.UpdatesClass, error)

Delete deletes scheduled messages.

func (*ScheduledManager) Get

Get gets scheduled messages.

func (*ScheduledManager) History

History gets scheduled messages history.

func (*ScheduledManager) HistoryWithHash

func (m *ScheduledManager) HistoryWithHash(ctx context.Context, hash int64) (tg.ModifiedMessagesMessages, error)

HistoryWithHash gets scheduled messages history.

func (*ScheduledManager) Send

func (m *ScheduledManager) Send(ctx context.Context, id int, ids ...int) (tg.UpdatesClass, error)

Send sends scheduled messages.

type SearchDocumentBuilder

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

SearchDocumentBuilder is a Document media option which uses messages.getDocumentByHash to find document.

See https://core.telegram.org/method/messages.getDocumentByHash.

See https://core.telegram.org/api/files#re-using-pre-uploaded-files.

func DocumentByHash

func DocumentByHash(
	hash []byte, size int64, mime string,
	caption ...StyledTextOption,
) *SearchDocumentBuilder

DocumentByHash finds document by hash and adds as attachment.

See https://core.telegram.org/method/messages.getDocumentByHash.

See https://core.telegram.org/api/files#re-using-pre-uploaded-files.

func (*SearchDocumentBuilder) Query

Query sets query field of InputMediaDocument.

func (*SearchDocumentBuilder) TTL

TTL sets time to live of self-destructing document.

func (*SearchDocumentBuilder) TTLSeconds

func (u *SearchDocumentBuilder) TTLSeconds(ttl int) *SearchDocumentBuilder

TTLSeconds sets time to live in seconds of self-destructing document.

type Sender

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

Sender is a message sending helper.

func NewSender

func NewSender(raw *tg.Client) *Sender

NewSender creates a new Sender.

func (*Sender) Answer

func (s *Sender) Answer(
	uctx tg.Entities,
	upd AnswerableMessageUpdate,
	decorators ...peer.PromiseDecorator,
) *RequestBuilder

Answer uses given message update to create message for same chat.

func (*Sender) ClearAllDrafts

func (s *Sender) ClearAllDrafts(ctx context.Context) error

ClearAllDrafts clears all drafts in all peers.

func (*Sender) Delete

func (s *Sender) Delete() *DeleteBuilder

Delete creates new DeleteBuilder.

func (*Sender) Inline

func (s *Sender) Inline(upd InlineUpdate) *inline.ResultBuilder

Inline creates new inline.ResultBuilder using given update.

func (*Sender) JoinHash

func (s *Sender) JoinHash(ctx context.Context, hash string) (tg.UpdatesClass, error)

JoinHash joins to private chat using given hash.

func (s *Sender) JoinLink(ctx context.Context, link string) (tg.UpdatesClass, error)

JoinLink joins to private chat using given link or hash. Input examples:

t.me/+AAAAAAAAAAAAAAAA
https://t.me/+AAAAAAAAAAAAAAAA
t.me/joinchat/AAAAAAAAAAAAAAAA
https://t.me/joinchat/AAAAAAAAAAAAAAAA
tg:join?invite=AAAAAAAAAAAAAAAA
tg://join?invite=AAAAAAAAAAAAAAAA

func (*Sender) Peer

func (s *Sender) Peer(uctx tg.Entities, upd PeerUpdate, decorators ...peer.PromiseDecorator) *RequestBuilder

Peer uses given peer update to create message for same chat.

func (*Sender) PeerPromise

func (s *Sender) PeerPromise(p peer.Promise, decorators ...peer.PromiseDecorator) *RequestBuilder

PeerPromise uses given peer promise to create new message builder.

func (*Sender) Reply

func (s *Sender) Reply(uctx tg.Entities, upd AnswerableMessageUpdate, decorators ...peer.PromiseDecorator) *Builder

Reply uses given message update to create message for same chat and create a reply. Shorthand for

sender.Answer(uctx, upd).ReplyMsg(upd.GetMessage())

func (*Sender) Resolve

func (s *Sender) Resolve(from string, decorators ...peer.PromiseDecorator) *RequestBuilder

Resolve uses given text to create new message builder. It resolves peer of message using Sender's PeerResolver. Input examples:

@telegram
telegram
t.me/telegram
https://t.me/telegram
tg:resolve?domain=telegram
tg://resolve?domain=telegram
+13115552368
+1 (311) 555-0123
+1 311 555-6162
Example
package main

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

	"bitbucket.org/hokego/hokego-td/telegram"
	"bitbucket.org/hokego/hokego-td/telegram/message"
	"bitbucket.org/hokego/hokego-td/telegram/message/peer"
	"bitbucket.org/hokego/hokego-td/tg"
)

func resolve(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))

		// Resolve and return input peer for @misato.
		_, err := sender.Resolve("misato").AsInputPeer(ctx)
		if err != nil {
			return err
		}

		// Resolve and join channel @seele.
		// If @seele is a user, not channel, error would be returned.
		_, err = sender.Resolve("seele", peer.OnlyChannel).Join(ctx)
		if err != nil {
			return err
		}

		return nil
	})
}

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

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

func (s *Sender) ResolveDeeplink(link string, decorators ...peer.PromiseDecorator) *RequestBuilder

ResolveDeeplink uses given deeplink to create new message builder. Deeplink is a URL like https://t.me/telegram. It resolves peer of message using Sender's PeerResolver. Input examples:

t.me/telegram
https://t.me/telegram
tg:resolve?domain=telegram
tg://resolve?domain=telegram

func (*Sender) ResolveDomain

func (s *Sender) ResolveDomain(domain string, decorators ...peer.PromiseDecorator) *RequestBuilder

ResolveDomain uses given domain to create new message builder. It resolves peer of message using Sender's PeerResolver. Can has prefix with @ or not. Input examples:

@telegram
telegram

func (*Sender) ResolvePhone

func (s *Sender) ResolvePhone(phone string, decorators ...peer.PromiseDecorator) *RequestBuilder

ResolvePhone uses given phone to create new peer promise. It resolves peer of message using given Resolver. Input example:

+13115552368
+1 (311) 555-0123
+1 311 555-6162

NB: ResolvePhone just deletes any non-digit symbols from phone argument. For now, Telegram sends contact number as string like "13115552368".

func (*Sender) Self

func (s *Sender) Self() *RequestBuilder

Self creates a new message builder to send it to yourself. It means that message will be sent to your Saved Messages folder.

func (*Sender) To

To uses given peer to create new message builder.

func (*Sender) WithRand

func (s *Sender) WithRand(r io.Reader) *Sender

WithRand sets random ID source.

func (*Sender) WithResolver

func (s *Sender) WithResolver(resolver peer.Resolver) *Sender

WithResolver sets peer resolver to use.

func (*Sender) WithUploader

func (s *Sender) WithUploader(u Uploader) *Sender

WithUploader sets file uploader to use.

type StyledTextOption

type StyledTextOption = styling.StyledTextOption

StyledTextOption is an option for styling text.

type TypingActionBuilder

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

TypingActionBuilder is a helper to create and send typing actions.

See https://core.telegram.org/method/messages.setTyping.

See https://core.telegram.org/type/SendMessageAction.

func (*TypingActionBuilder) Cancel

func (b *TypingActionBuilder) Cancel(ctx context.Context) error

Cancel sends SendMessageCancelAction.

func (*TypingActionBuilder) ChooseContact

func (b *TypingActionBuilder) ChooseContact(ctx context.Context) error

ChooseContact sends SendMessageChooseContactAction.

func (*TypingActionBuilder) ChooseSticker

func (b *TypingActionBuilder) ChooseSticker(ctx context.Context) error

ChooseSticker sends SendMessageChooseStickerAction.

func (*TypingActionBuilder) Custom

Custom sends given action.

func (*TypingActionBuilder) EmojiInteraction

func (b *TypingActionBuilder) EmojiInteraction(ctx context.Context, emoticon string, msgID int, interaction tg.DataJSON) error

EmojiInteraction sends SendMessageEmojiInteraction.

func (*TypingActionBuilder) EmojiInteractionSeen

func (b *TypingActionBuilder) EmojiInteractionSeen(ctx context.Context, emoticon string) error

EmojiInteractionSeen sends SendMessageEmojiInteractionSeen.

func (*TypingActionBuilder) GamePlay

func (b *TypingActionBuilder) GamePlay(ctx context.Context) error

GamePlay sends SendMessageGamePlayAction.

func (*TypingActionBuilder) GeoLocation

func (b *TypingActionBuilder) GeoLocation(ctx context.Context) error

GeoLocation sends SendMessageGeoLocationAction.

func (*TypingActionBuilder) HistoryImport

func (b *TypingActionBuilder) HistoryImport(ctx context.Context, progress int) error

HistoryImport sends SendMessageHistoryImportAction.

func (*TypingActionBuilder) RecordAudio

func (b *TypingActionBuilder) RecordAudio(ctx context.Context) error

RecordAudio sends SendMessageRecordAudioAction.

func (*TypingActionBuilder) RecordRound

func (b *TypingActionBuilder) RecordRound(ctx context.Context) error

RecordRound sends SendMessageRecordRoundAction.

func (*TypingActionBuilder) RecordVideo

func (b *TypingActionBuilder) RecordVideo(ctx context.Context) error

RecordVideo sends SendMessageRecordVideoAction.

func (*TypingActionBuilder) SpeakingInGroupCall

func (b *TypingActionBuilder) SpeakingInGroupCall(ctx context.Context) error

SpeakingInGroupCall sends SpeakingInGroupCallAction.

func (*TypingActionBuilder) ThreadID

func (b *TypingActionBuilder) ThreadID(id int) *TypingActionBuilder

ThreadID sets thread ID to send.

func (*TypingActionBuilder) ThreadMsg

ThreadMsg sets message's ID as thread ID to send.

func (*TypingActionBuilder) Typing

func (b *TypingActionBuilder) Typing(ctx context.Context) error

Typing sends SendMessageTypingAction.

func (*TypingActionBuilder) UploadAudio

func (b *TypingActionBuilder) UploadAudio(ctx context.Context, progress int) error

UploadAudio sends SendMessageUploadAudioAction.

func (*TypingActionBuilder) UploadDocument

func (b *TypingActionBuilder) UploadDocument(ctx context.Context, progress int) error

UploadDocument sends SendMessageUploadDocumentAction.

func (*TypingActionBuilder) UploadPhoto

func (b *TypingActionBuilder) UploadPhoto(ctx context.Context, progress int) error

UploadPhoto sends SendMessageUploadPhotoAction.

func (*TypingActionBuilder) UploadRound

func (b *TypingActionBuilder) UploadRound(ctx context.Context, progress int) error

UploadRound sends SendMessageUploadRoundAction.

func (*TypingActionBuilder) UploadVideo

func (b *TypingActionBuilder) UploadVideo(ctx context.Context, progress int) error

UploadVideo sends SendMessageUploadVideoAction.

type UploadBuilder

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

UploadBuilder is an attachment uploading helper.

func (*UploadBuilder) AsInputFile

func (u *UploadBuilder) AsInputFile(ctx context.Context) (tg.InputFileClass, error)

AsInputFile uploads and returns uploaded file entity.

func (*UploadBuilder) Audio

func (u *UploadBuilder) Audio(ctx context.Context, caption ...StyledTextOption) (tg.UpdatesClass, error)

Audio uploads and sends audio file.

func (*UploadBuilder) File

func (u *UploadBuilder) File(ctx context.Context, caption ...StyledTextOption) (tg.UpdatesClass, error)

File uploads and sends plain file.

func (*UploadBuilder) GIF

func (u *UploadBuilder) GIF(ctx context.Context, caption ...StyledTextOption) (tg.UpdatesClass, error)

GIF uploads and sends gif file.

func (*UploadBuilder) Photo

func (u *UploadBuilder) Photo(ctx context.Context, caption ...StyledTextOption) (tg.UpdatesClass, error)

Photo uploads and sends photo.

func (*UploadBuilder) RoundVideo

func (u *UploadBuilder) RoundVideo(ctx context.Context, caption ...StyledTextOption) (tg.UpdatesClass, error)

RoundVideo uploads and sends round video.

func (*UploadBuilder) Sticker

func (u *UploadBuilder) Sticker(ctx context.Context, caption ...StyledTextOption) (tg.UpdatesClass, error)

Sticker uploads and sends sticker.

func (*UploadBuilder) Video

func (u *UploadBuilder) Video(ctx context.Context, caption ...StyledTextOption) (tg.UpdatesClass, error)

Video uploads and sends video.

func (*UploadBuilder) Voice

func (u *UploadBuilder) Voice(ctx context.Context) (tg.UpdatesClass, error)

Voice uploads and sends voice message.

type UploadOption

type UploadOption interface {
	// contains filtered or unexported methods
}

UploadOption is a UploadBuilder creation option.

func FromBytes

func FromBytes(name string, data []byte) UploadOption

FromBytes uploads file from given byte slice.

func FromFS

func FromFS(filesystem fs.FS, path string) UploadOption

FromFS uploads file from given path using given fs.FS.

func FromFile

func FromFile(f uploader.File) UploadOption

FromFile uploads given File. NB: FromFile does not close given file.

func FromPath

func FromPath(path string) UploadOption

FromPath uploads file from given path.

func FromReader

func FromReader(name string, r io.Reader) UploadOption

FromReader uploads file from given io.Reader. NB: totally stream should not exceed the limit for small files (10 MB as docs says, may be a bit bigger).

func FromSource

func FromSource(src source.Source, rawURL string) UploadOption

FromSource uploads file from given URL using given Source.

func FromURL

func FromURL(rawURL string) UploadOption

FromURL uploads file from given URL.

func Upload

func Upload(promise FilePromise) UploadOption

Upload creates new upload options using given promise.

Example
package main

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

	"github.com/go-faster/errors"

	"bitbucket.org/hokego/hokego-td/telegram"
	"bitbucket.org/hokego/hokego-td/telegram/message"
	"bitbucket.org/hokego/hokego-td/tg"
)

func filePromiseResult(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))
		r := sender.Resolve("@durov")

		var result tg.InputFileClass
		_, err := r.Upload(message.Upload(func(ctx context.Context, b message.Uploader) (tg.InputFileClass, error) {
			r, err := b.FromPath(ctx, "file.jpg")
			if err != nil {
				return nil, err
			}

			result = r
			return r, nil
		})).Photo(ctx)
		if err != nil {
			return errors.Wrap(err, "upload photo")
		}

		_, err = r.Media(ctx, message.UploadedDocument(result))
		if err != nil {
			return errors.Wrap(err, "upload document")
		}

		return nil
	})
}

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

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

type UploadedDocumentBuilder

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

UploadedDocumentBuilder is a UploadedDocument media option.

func File

File adds document attachment and forces it to be used as plain file, not media.

func GIF

GIF adds gif attachment.

Example
package main

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

	"bitbucket.org/hokego/hokego-td/telegram"
	"bitbucket.org/hokego/hokego-td/telegram/message"
	"bitbucket.org/hokego/hokego-td/tg"
)

func sendGif(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))

		// Uploads and sends gif to the @durovschat.
		if _, err := sender.Resolve("https://t.me/durovschat").
			Upload(message.FromPath("./rickroll.gif")).
			GIF(ctx); err != nil {
			return err
		}

		return nil
	})
}

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

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

func UploadedDocument

func UploadedDocument(file tg.InputFileClass, caption ...StyledTextOption) *UploadedDocumentBuilder

UploadedDocument adds document attachment.

func (*UploadedDocumentBuilder) Attributes

Attributes adds given attributes to the document. Attribute specify the type of the document (video, audio, voice, sticker, etc.).

func (*UploadedDocumentBuilder) Audio

Audio creates new AudioDocumentBuilder to create audio attachment.

func (*UploadedDocumentBuilder) Filename

Filename sets name of uploaded file.

func (*UploadedDocumentBuilder) ForceFile

ForceFile sets flag to force the media file to be uploaded as document.

func (*UploadedDocumentBuilder) GIF

GIF add attributes to create GIF attachment.

func (*UploadedDocumentBuilder) HasStickers

HasStickers sets flag that document attachment has stickers.

func (*UploadedDocumentBuilder) MIME

MIME sets MIME type of document.

func (*UploadedDocumentBuilder) NosoundVideo

NosoundVideo sets flag that the specified document is a video file with no audio tracks (a GIF animation (even as MPEG4), for example).

func (*UploadedDocumentBuilder) RoundVideo

RoundVideo creates new VideoDocumentBuilder to create round video attachment.

func (*UploadedDocumentBuilder) Stickers

Stickers adds attached mask stickers.

func (*UploadedDocumentBuilder) TTL

TTL sets time to live of self-destructing document.

func (*UploadedDocumentBuilder) TTLSeconds

TTLSeconds sets time to live in seconds of self-destructing document.

func (*UploadedDocumentBuilder) Thumb

Thumb sets thumbnail of the document, uploaded as for the file.

func (*UploadedDocumentBuilder) UploadedSticker

func (u *UploadedDocumentBuilder) UploadedSticker() *UploadedStickerBuilder

UploadedSticker creates new UploadedStickerBuilder to create sticker attachment.

func (*UploadedDocumentBuilder) Video

Video creates new VideoDocumentBuilder to create video attachment.

func (*UploadedDocumentBuilder) Voice

Voice creates new AudioDocumentBuilder to create voice attachment.

type UploadedPhotoBuilder

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

UploadedPhotoBuilder is a UploadedPhoto media option.

func UploadedPhoto

func UploadedPhoto(file tg.InputFileClass, caption ...StyledTextOption) *UploadedPhotoBuilder

UploadedPhoto adds photo attachment.

func (*UploadedPhotoBuilder) Stickers

func (u *UploadedPhotoBuilder) Stickers(stickers ...FileLocation) *UploadedPhotoBuilder

Stickers adds attached mask stickers.

func (*UploadedPhotoBuilder) TTL

TTL sets time to live of self-destructing photo.

func (*UploadedPhotoBuilder) TTLSeconds

func (u *UploadedPhotoBuilder) TTLSeconds(ttl int) *UploadedPhotoBuilder

TTLSeconds sets time to live in seconds of self-destructing photo.

type UploadedStickerBuilder

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

UploadedStickerBuilder is a uploaded sticker media option.

func UploadedSticker

func UploadedSticker(file tg.InputFileClass, caption ...StyledTextOption) *UploadedStickerBuilder

UploadedSticker adds uploaded sticker attachment.

func (*UploadedStickerBuilder) Alt

Alt sets alternative emoji representation of sticker.

func (*UploadedStickerBuilder) Mask

Mask sets flag that is a mask sticker.

func (*UploadedStickerBuilder) MaskCoords

func (u *UploadedStickerBuilder) MaskCoords(maskCoords tg.MaskCoords) *UploadedStickerBuilder

MaskCoords sets mask coordinates (if this is a mask sticker, attached to a photo).

func (*UploadedStickerBuilder) StickerSet

StickerSet sets associated sticker set.

type Uploader

type Uploader interface {
	FromFile(ctx context.Context, f uploader.File) (tg.InputFileClass, error)
	FromPath(ctx context.Context, path string) (tg.InputFileClass, error)
	FromFS(ctx context.Context, filesystem fs.FS, path string) (tg.InputFileClass, error)
	FromReader(ctx context.Context, name string, f io.Reader) (tg.InputFileClass, error)
	FromBytes(ctx context.Context, name string, b []byte) (tg.InputFileClass, error)
	FromURL(ctx context.Context, rawURL string) (tg.InputFileClass, error)
	FromSource(ctx context.Context, src source.Source, rawURL string) (tg.InputFileClass, error)
}

Uploader is an abstraction for Telegram file uploader.

type VideoDocumentBuilder

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

VideoDocumentBuilder is a Video media option.

func RoundVideo

func RoundVideo(file tg.InputFileClass, caption ...StyledTextOption) *VideoDocumentBuilder

RoundVideo adds round video attachment.

func Video

func Video(file tg.InputFileClass, caption ...StyledTextOption) *VideoDocumentBuilder

Video adds video attachment.

func (*VideoDocumentBuilder) Duration

func (u *VideoDocumentBuilder) Duration(duration time.Duration) *VideoDocumentBuilder

Duration sets duration of video file.

func (*VideoDocumentBuilder) DurationSeconds

func (u *VideoDocumentBuilder) DurationSeconds(duration int) *VideoDocumentBuilder

DurationSeconds sets duration in seconds.

func (*VideoDocumentBuilder) Resolution

func (u *VideoDocumentBuilder) Resolution(w, h int) *VideoDocumentBuilder

Resolution sets resolution of this video.

func (*VideoDocumentBuilder) Round

Round sets flag to mark this video as round.

func (*VideoDocumentBuilder) SupportsStreaming

func (u *VideoDocumentBuilder) SupportsStreaming() *VideoDocumentBuilder

SupportsStreaming sets flag to mark this video as which supports streaming.

Directories

Path Synopsis
Package entity contains message formatting and styling helpers.
Package entity contains message formatting and styling helpers.
Package html contains HTML styling options.
Package html contains HTML styling options.
Package inline contains inline query results builder.
Package inline contains inline query results builder.
internal
mkrun
Package mkrun contains some helpers for generation scripts.
Package mkrun contains some helpers for generation scripts.
mktyping
Binary mktyping generates TypingActionBuilder.
Binary mktyping generates TypingActionBuilder.
Package markup contain bots inline markup builder.
Package markup contain bots inline markup builder.
Package peer conatains some peer resolving and extracting helpers.
Package peer conatains some peer resolving and extracting helpers.
Package styling contains styling options for Telegram messages.
Package styling contains styling options for Telegram messages.
Package unpack contains some updates result unpacking helpers.
Package unpack contains some updates result unpacking helpers.

Jump to

Keyboard shortcuts

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