Sreyas-Sreelal / tgconnector

Telegram connector for samp
GNU General Public License v3.0
38 stars 4 forks source link

suggestion: TGMessageUser(TGBot:bot, TGUser:recipient, const text[] ); #6

Closed Ryder17z closed 2 years ago

Ryder17z commented 4 years ago

Useful for replying to PM's E.g. pointing user to the correct group to join

Useful for not spamming a group while developing a bot (i know you could make a throw-away chat for this but i'd rather not)

issue-label-bot[bot] commented 4 years ago

Issue-Label Bot is automatically applying the label feature_request to this issue, with a confidence of 0.98. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

Sreyas-Sreelal commented 4 years ago

Telegram bots have some limitations regarding sending private messages. You can't directly message any user, for that the user has to start a conversation with the bot and the API cannot directly message them using their username like we can do for channels.

But you still can message a user with their userid as chatid. For example

TGSendMessage(g_bot,TGChatId:"your userid here","my message");

The userid id can be get using this plugin or as well as using some bot services like @jsondumpbot

Ryder17z commented 4 years ago

I'm aware of those limitations yes.

However, i'm having difficulties making the bot reply to a pm.

public OnTGMessage(TGBot:bot,TGUser:fromid,TGMessage:messageid) {

    if(g_bot != bot){
        return 1;
    }

    new
        message[50],
        username[24],
        chatname[56],
        server_msg[128];

    TGCacheGetMessage(message);
    TGCacheGetUserName(username);
    TGCacheGetChatName(chatname);

    format(server_msg,128,"[%s] %s(%d): %s",chatname,username,_:fromid,message);
    SendClientMessageToAll(-1,server_msg);
    printf(server_msg);

    new cmd[24], user[128], tmp[324];
    if(!sscanf(server_msg, "s[24]s[128]s[324]", cmd, user, tmp)) // edited so it actually works
    {
        if((tmp[0] == 'h' && tmp[1] == 'i')
        || (tmp[0] == 'H' && tmp[1] == 'I'))
        {
            TGSendMessage(g_bot,TGUser:fromid,"hello");
            //  error 035: argument type mismatch (argument 2)
            TGSendMessage(g_bot,TGChatId:fromid,"hello");
            //  error 035: argument type mismatch (argument 2)
            TGSendMessage(g_bot,_:fromid,"hello");
            //  error 035: argument type mismatch (argument 2)
        }
    }

    return 1;
}
Sreyas-Sreelal commented 4 years ago

You can always reply to a message in the group or the private chat that's already been initiated by user. Just specify reply_id in TGSendMessage In your case

TGSendMessage(g_bot,your_chatid,"hello",reply_id=messageid);

And you can't use UserId as Chatid or in otherwords send a private message to an user, unless you initiate a pm session with bot.So what you trying to do won't work.

Ryder17z commented 4 years ago

But bots can send messages to an already started private convo, this is what confuses me.

Sreyas-Sreelal commented 4 years ago

But bots can send messages to an already started private convo, this is what confuses me.

It can send messages to already started conversation.

Just grab the user's id and use it as chat id. Chat id should be a string so convert userid to string first and tag it with ChatId