G3rard wrote:@Simonrg, is there a way to change the scripts in the LUA folder so these send the message to TelegramChatId as defined in DomoticzData.sh?
Now it's sending the respons to the person who has sent the message to the group and I want the bot to send the answer to the group.
I have this working for the bash scripts, by changing Send(Msg)To. Should I make the changes in dtgbot.lua?
My corrected answer:
Thanks, I now understand what is going on

and if we change from using the from.id to chat.id, then if you send a private message dtgbot will respond privately to you and if you send a group chat then it should respond to the group. This should mean you don't have to hard code anything in either the bash scripts or the Lua code.
Please could you comment out around line 373 (within on_msg_receive function) in dtgbot.lua, i.e. the first line below and add the comment plus the extra line - so basically msg_from will now be msg.chat.id rather than msg.from.id:
Code: Select all
-- msg_from = msg.from.id
-- Changed from from.id to chat.id to allow group chats to work as expected.
msg_from = msg.chat.id
Let me know if this solves your problem with group chats.
My first answer, just kept for the thought process

:
It would be easy to change, but you would loose any flexibility and according to the documentation of the api you shouldn't need to do this.
Are you sure you are sending your message as Group Chat message and not as a private message? (I hadn't understood that from was the identified as the user rather than the group chat).
If you look at the api reference -
https://core.telegram.org/bots/api#message - it returns a unique identifier for the user or the group chat, it is this identifier which is used to return the message. So it would appear that your message is being interpreted as private and not one from a group, hence it is being returned to you not to the group.
I am using the getUpdates method to retrieve the messages,
https://core.telegram.org/bots/api#getupdates, this return updates,
https://core.telegram.org/bots/api#update, I use the messages,
https://core.telegram.org/bots/api#message, the message should contain either a user
https://core.telegram.org/bots/api#user or group chat
https://core.telegram.org/bots/api#groupchat, both of which contain a unique id which will be user_id or group_id. Actually from.id is always the user, it is only chat.id which changes from user to group chat,

I have been using the from.id, using the chat.id should make it behave as I assumed it was already.
Full on_msg_receive function:
Code: Select all
function on_msg_receive (msg)
if started == 0 then
return
end
if msg.out then
return
end
if msg.text then -- check if message is text
-- ReceivedText = string.lower(msg.text)
ReceivedText = msg.text
-- if msg.to.type == "chat" then -- check if the command was given in a group chat
-- msg_from = msg.to.print_name -- if yes, take the group name as a destination for the reply
-- else
-- msg_from = msg.from.print_name -- if no, take the users name as destination for the reply
-- end
-- msg_from = msg.from.id
-- Changed from from.id to chat.id to allow group chats to work as expected.
msg_from = msg.chat.id
msg_id =msg.message_id
if HandleCommand(ReceivedText, tostring(msg_from),msg_id) == 1 then
print "Succesfully handled incoming request"
else
print "Invalid command received"
print(msg_from)
send_msg(msg_from,'⚡️ INVALID COMMAND ⚡️',msg_id)
-- os.execute("sleep 5")
-- Help(tostring (msg_from))
end
end
-- mark_read(msg_from)
end