AmarnathCJD / gogram

Full-native implementation of MTProto protocol on Golang.
GNU General Public License v3.0
207 stars 41 forks source link

Issue in handling multiple users if multiple ids passed to User parameter in AddMessageHandle #48

Closed TAMILVIP007 closed 1 year ago

TAMILVIP007 commented 1 year ago

Bug Description

The gogram library exhibits incorrect behavior when multiple user IDs are passed to the Users field in the AddMessageHandler function. While the code works flawlessly when a single user ID is provided, it fails to handle multiple user IDs properly.

When multiple user IDs are specified in the Users field, the message handler is expected to be triggered for each user ID individually. However, in the current implementation, the message handler fails to execute for any of the provided user IDs.

This bug severely limits the functionality of the gogram library in scenarios where message handlers need to be registered for multiple users simultaneously.

To Reproduce

Steps to reproduce the behavior:

  1. Initialize the bot using the following code:
package src

import (
    "fmt"
    "log"

    "github.com/amarnathcjd/gogram/telegram"
)

func InitBot() *telegram.Client {
    log.Println("Initializing bot...")
    client, _ := telegram.NewClient(telegram.ClientConfig{
        AppID:    Envars.AppId,
        AppHash:  Envars.AppHash,
        LogLevel: telegram.LogInfo,
        Session:  "./session.session",
    })

    if err := client.Connect(); err != nil {
        panic(err)
    }
    if err := client.LoginBot(Envars.Token); err != nil {
        panic(err)
    }
    client.AddMessageHandler("/text", AuthChatHandler, &telegram.Filters{Users: Envars.Devs})
    return client
}
  1. Pass multiple user IDs to the Users field in the AddMessageHandler function, as shown below:
client.AddMessageHandler("/text", AuthChatHandler, &telegram.Filters{Users: []int{123, 456, 789}})

1, Trigger the message handler by sending a relevant message.

  1. Observe that the code fails to handle multiple user IDs correctly, and the message handler does not execute for any of the provided user IDs.

Expected Behavior

The expected behavior is that the gogram library should handle multiple user IDs properly in the AddMessageHandler function. Specifically, the message handler should be triggered individually for each user ID provided in the Users field.

Actual Behavior

Contrary to expectations, the current implementation of the gogram library fails to handle multiple user IDs correctly. When multiple user IDs are specified, the message handler does not execute for any of the provided user IDs.

Environment Details

  1. Operating System: Linux
  2. Go Version: 1.20

Additional Information

The version of the gogram library being used: github.com/amarnathcjd/gogram v0.0.0-20230616162607-84be75d00aa5

Steps Taken to Resolve the Issue

I have examined the code implementation thoroughly and ensured that the user IDs are correctly provided to the AddMessageHandler function. Additionally, I have reviewed the available documentation and examples for the gogram library but couldn't find any specific guidance on handling multiple user IDs in the AddMessageHandler function.

AmarnathCJD commented 1 year ago

https://github.com/AmarnathCJD/gogram/commit/6cd498afaeee593e16ab4d95ab0b1f26601d7003