Задать вопрос
  • Почему ошибка в SendMessageParams?

    А почему бы вам не установить курсор на "SendMessageParams" и не нажать правой кнопкой мыши на этом слове, да и не перейти к объявлению типа, чтобы просто посмотреть, а какие же там поля требуются в этой структуре?
    И, странное дело, нет такого поля ReplyToMessageID у типа SendMessageParams, о чём вам прямо и говорит компилятор.

    Документация и исходный код - вот источник правды, а не устаревшие туториалы школьников на ютубчике.

    // SendMessageParams - Represents parameters of sendMessage method.
    type SendMessageParams struct {
    	// BusinessConnectionID - Optional. Unique identifier of the business connection on behalf of which the
    	// message will be sent
    	BusinessConnectionID string `json:"business_connection_id,omitempty"`
    
    	// ChatID - Unique identifier for the target chat or username of the target channel (in the format
    	// @channel_username)
    	ChatID ChatID `json:"chat_id"`
    
    	// MessageThreadID - Optional. Unique identifier for the target message thread (topic) of the forum; for
    	// forum supergroups only
    	MessageThreadID int `json:"message_thread_id,omitempty"`
    
    	// Text - Text of the message to be sent, 1-4096 characters after entities parsing
    	Text string `json:"text"`
    
    	// ParseMode - Optional. Mode for parsing entities in the message text. See formatting options
    	// (https://core.telegram.org/bots/api#formatting-options) for more details.
    	ParseMode string `json:"parse_mode,omitempty"`
    
    	// Entities - Optional. A JSON-serialized list of special entities that appear in message text, which can be
    	// specified instead of parse_mode
    	Entities []MessageEntity `json:"entities,omitempty"`
    
    	// LinkPreviewOptions - Optional. Link preview generation options for the message
    	LinkPreviewOptions *LinkPreviewOptions `json:"link_preview_options,omitempty"`
    
    	// DisableNotification - Optional. Sends the message silently
    	// (https://telegram.org/blog/channels-2-0#silent-messages). Users will receive a notification with no sound.
    	DisableNotification bool `json:"disable_notification,omitempty"`
    
    	// ProtectContent - Optional. Protects the contents of the sent message from forwarding and saving
    	ProtectContent bool `json:"protect_content,omitempty"`
    
    	// MessageEffectID - Optional. Unique identifier of the message effect to be added to the message; for
    	// private chats only
    	MessageEffectID string `json:"message_effect_id,omitempty"`
    
    	// ReplyParameters - Optional. Description of the message to reply to
    	ReplyParameters *ReplyParameters `json:"reply_parameters,omitempty"`
    
    	// ReplyMarkup - Optional. Additional interface options. A JSON-serialized object for an inline keyboard
    	// (https://core.telegram.org/bots/features#inline-keyboards), custom reply keyboard
    	// (https://core.telegram.org/bots/features#keyboards), instructions to remove a reply keyboard or to force a
    	// reply from the user
    	ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
    }


    А если точно так же перейти к определению типа поля ReplyParameters, то можно увидеть как раз то самое искомое вами поле MessageID

    // ReplyParameters - Describes reply parameters for the message that is being sent.
    type ReplyParameters struct {
    	// MessageID - Identifier of the message that will be replied to in the current chat, or in the chat chat_id
    	// if it is specified
    	MessageID int `json:"message_id"`
    
    	// ChatID - Optional. If the message to be replied to is from a different chat, unique identifier for the
    	// chat or username of the channel (in the format @channel_username). Not supported for messages sent on behalf
    	// of a business account.
    	ChatID ChatID `json:"chat_id,omitempty"`
    
    	// AllowSendingWithoutReply - Optional. Pass True if the message should be sent even if the specified
    	// message to be replied to is not found. Always False for replies in another chat or forum topic. Always True
    	// for messages sent on behalf of a business account.
    	AllowSendingWithoutReply bool `json:"allow_sending_without_reply,omitempty"`
    
    	// Quote - Optional. Quoted part of the message to be replied to; 0-1024 characters after entities parsing.
    	// The quote must be an exact substring of the message to be replied to, including bold, italic, underline,
    	// strikethrough, spoiler, and custom_emoji entities. The message will fail to send if the quote isn't found in
    	// the original message.
    	Quote string `json:"quote,omitempty"`
    
    	// QuoteParseMode - Optional. Mode for parsing entities in the quote. See formatting options
    	// (https://core.telegram.org/bots/api#formatting-options) for more details.
    	QuoteParseMode string `json:"quote_parse_mode,omitempty"`
    
    	// QuoteEntities - Optional. A JSON-serialized list of special entities that appear in the quote. It can be
    	// specified instead of quote_parse_mode.
    	QuoteEntities []MessageEntity `json:"quote_entities,omitempty"`
    
    	// QuotePosition - Optional. Position of the quote in the original message in UTF-16 code units
    	QuotePosition int `json:"quote_position,omitempty"`
    }


    Итого, в вашем случае будет как-то так:

    id, ticket, reply_message := db.GetTicketAndMessage(message.ReplyToMessage.MessageID, user.ID)
    	if ticket == nil {
    		_, _ = bot.SendMessage(&telego.SendMessageParams{
    			ChatID:           telego.ChatID{ID: message.Chat.ID},
    			Text:             "This ticket or message does not exist.",
    			ReplyParameters:  &telego.ReplyParameters{
                                    MessageID: message.MessageID
                            },
    			ParseMode:        "HTML",
    		})
    		return
    	}
    Ответ написан
    4 комментария
  • Как получить группы, в которых состоит пользователь?

    @NortheR73
    системный инженер
    Я нашел func GroupIds пакета "os/user"
    вам нужен модуль/пакет/библиотека для Go для работы с LDAP/Active Directory...
    Далее в коде вы выполняете подключение к AD и LDAP-запрос с фильтром вида
    (&(objectClass=user)(sAMAccountName=yourUserName)(memberof=CN=YourGroup,OU=UsersOU,DC=YourDomain,DC=YourDomainExt))

    должен вернуться ненулевой результат, если конкретный пользователь (yourUserName) входит в конкретную доменную группу (YourGroup)
    Ответ написан
    Комментировать
  • Как получить группы, в которых состоит пользователь?

    Вот ответ для вашего конкретного случая в Windows.

    package main
    
    import (
    	"fmt"
    	"os/exec"
    	"strings"
    )
    
    func getGroups() ([]string, error) {
    	var groups []string
    
    	patch := "/groups"
    	cmd := exec.Command("whoami", patch)
    	output, err := cmd.Output()
    	if err != nil {
    		return nil, err
    	}
    
    	lines := strings.Split(string(output), "\n")
    	for _, line := range lines {
    		if strings.HasPrefix(line, "S-1-5-21") {
    			groups = append(groups, line)
    		}
    	}
    
    	return groups, nil
    }
    
    func main() {
    	groups, err := getGroups()
    	if err != nil {
    		fmt.Printf("Ошибка получения групп пользователя: %v\n", err)
    		return
    	}
    
    	fmt.Println("Группы пользователя:", groups)
    }
    Ответ написан
    21 комментарий