How to disable update messages of a channel at the start of running the program

Hi Dylan,

(I wrote this question on go forum and have not received reply yet.)

I’m working on a telegram Golang program using TDlib,
everytime that I run the program it will bring about 20 messages from about an hour or more before,
I want to refrain from getting them, I would be thankful for your comments.

Usually, I receive all messages missed while the instance wasn’t active. If there were a lot of missed messages, I will receive a lot of updateNewMessage updates soon after start.

I want to skip all updates about messages, which were sent before instance launch, by examining their send date.

my program is something like this:

// Send “/start” text every 5 seconds to Foursquare bot chat
go func() {
// Should get chatID somehow, check out “getChats” example
chatID := int64(198529620) // Foursquare bot chat id

inputMsgTxt := tdlib.NewInputMessageText(tdlib.NewFormattedText(“/start”, nil), true, true)
client.SendMessage(chatID, 0, 0, nil, nil, inputMsgTxt)

time.Sleep(5 * time.Second)
}()

// rawUpdates gets all updates comming from tdlib
rawUpdates := client.GetRawUpdatesChannel(100)
for update := range rawUpdates {
// Show all updates
fmt.Println(update.Data)
fmt.Print(“\n\n”)
}

I would be thankful for your comments.

Cheers

I don’t know anything about this library, but is there something in the update that contains a date? Could you check that date in your for update := range rawUpdates loop and skip printing all the ones you receive from times you don’t want?

Dear Sean,

Thanks for your email and help. The messages are something like following:

rawUpdates := client.GetRawUpdatesChannel(100)
for update := range rawUpdates {
// Show all updates

updateMsg := (update).(*tdlib.UpdateNewMessage)
msgText := updateMsg.Message.Content.(*tdlib.MessageText)
mangledText := strings.Replace(msgText.Text.Text, “AAA”, “BBB”, -1)
mangledText = strings.Replace(mangledText, “CCC”,“DDD”, -1)

fmt.Println(update.Data)
fmt.Print(“\n\n”)
}

I would be thankful for an example to apply the time on the messages and skipping the messages before that time.
Also, how can I define the start of run time to the program.

Cheers

Since there seems to be no godoc, you’ll need to refer to the ultimate documentation at GitHub - zelenin/go-tdlib: Go wrapper for TDLib (Telegram Database Library). UpdateNewMessage https://github.com/zelenin/go-tdlib/blob/master/client/type.go#L28979-L28983 has a *Message field, and Message has a Date field: https://github.com/zelenin/go-tdlib/blob/master/client/type.go#L6321-L6322.

 // Define the earliest time to allow.  https://pkg.go.dev/time#Date
 earlyTimeLimit := time.Date(2022, 9, 7, 12, 0, 0, 0, time.UTC).Unix(); 


 // Later, filter messages
  if updateMsg.Message.Date < earlyTimeLimit  {
    // Skip message that is too early.
    continue
  }

Same as what @mje said, but the Date field seems to be of type int32 in both the package that Jeff mentioned and the package that I found in my Google results: https://pkg.go.dev/github.com/Arman92/go-tdlib/v2/tdlib#Message

The NewMessage function in the package that I found (right under Message’s documentation) describes the date and editDate parameters as a “Unix timestamp.” You should be able to use time.Unix and pass that int32 value as the Unix function’s sec parameter (that function expects the parameter to be int64, so you’ll have to convert it). You can then do the date check that Jeff mentioned to see if it’s before the date you want.

If you want to get the date the program starts, you can have a global variable hold that date:

var programStartTime = time.Now()

1 Like

Dear @skillian and @mje,

Thanks for your help and suggestions, I could compile the program to avoid prior run-time updates.
And I think it works now.
In case I had problem, I will ask again.

Cheers

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.