Skip to content

Where is an example of userbot with getting updates? Is gotd async (Does new updates handle in goroutines)? #574

Answered by tdakkota
Mandofskii asked this question in Q&A
Discussion options

You must be logged in to vote

There is no difference between bot and user with getting updates.
You need to set UpdateHandler field in telegram.Options and pass it to NewClient constructor.

Also you can use tg.UpdateDispatcher to set handlers for specific updates.

Example echo userbot:

package main

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

	"golang.org/x/xerrors"

	"github.com/gotd/td/telegram"
	"github.com/gotd/td/telegram/auth"
	"github.com/gotd/td/telegram/message"
	"github.com/gotd/td/tg"
)

func echo(ctx context.Context) error {
	d := tg.NewUpdateDispatcher()
	// Create client using testing app_id and app_hash.
	// You can get it from https://my.telegram.org/apps.
	client := telegram.New…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@aliir74
Comment options

Answer selected by ernado
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
enhancement New feature or request
3 participants
Converted from issue

This discussion was converted from issue #463 on November 22, 2021 12:53.