
Gizmocuz,what do you think about this?
(I will give the install a try tomorrow, it is not a hard thing to do)
Moderator: leecollings
I thought 5.2 was now the standard version in Raspbian Wheezy.pvm wrote:The reason for asking is that it easier to use the standard supplied version of lua instead of the newer one.
Code: Select all
#install JQ
wget http://stedolan.github.io/jq/download/source/jq-1.4.tar.gz
tar -zxvf jq-1.4.tar.gz
rm jq-1.4.tar.gz
cd jq-1.4
./configure
make
sudo make install
Code: Select all
/usr/bin/lua: /home/pi/dtgbot/dtgbot.lua:316: bad argument #1 to 'len' (string expected, got nil)
stack traceback:
[C]: in function 'len'
/home/pi/dtgbot/dtgbot.lua:316: in function 'HandleCommand'
/home/pi/dtgbot/dtgbot.lua:375: in function 'on_msg_receive'
/home/pi/dtgbot/dtgbot.lua:440: in main chunk
[C]: in ?
Code: Select all
/usr/bin/lua: /home/pi/dtgbot/lua//devices.lua:19: bad argument #1 to 'pairs' (table expected, got nil)
stack traceback:
[C]: in function 'pairs'
/home/pi/dtgbot/lua//devices.lua:19: in function 'DevicesScenes'
/home/pi/dtgbot/lua//devices.lua:45: in function 'handler'
/home/pi/dtgbot/dtgbot.lua:291: in function 'HandleCommand'
/home/pi/dtgbot/dtgbot.lua:375: in function 'on_msg_receive'
/home/pi/dtgbot/dtgbot.lua:440: in main chunk
[C]: in ?
Code: Select all
pi@domoticzpi ~ $ sudo service dtgbot status
[FAIL] dtgbot is not running ... failed!
Have you checked the dtb.log.errors file?Heisenberg wrote:I still can't get the BOT running![]()
My corrected answer: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?
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
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
That works indeed! Thanks for the quick respons. It works for both the lua and bash scripts.simonrg wrote: My corrected answer:
Thanks, I now understand what is going onand 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:Let me know if this solves your problem with group chats.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
G3rard wrote:That works indeed! Thanks for the quick response. It works for both the lua and bash scripts.
When I send a message to the bot, it responds to me. When I send a message in the group, the bot responds to the group.
Great, looking forward to the new version. Your work is much appreciated!!!simonrg wrote:G3rard wrote:That works indeed! Thanks for the quick response. It works for both the lua and bash scripts.
When I send a message to the bot, it responds to me. When I send a message in the group, the bot responds to the group.
![]()
![]()
![]()
![]()
Phew / Great - I had been watching the issue with the group chat but I just couldn't understand what was wrong, it was only when I worked back through the api method by method, object by object, that I saw the ambiguity and why there was both a from and chat object which seemed to contain the same information at least for a private message, that it dawned on me that it wouldn't in the case of a group chat.
In the end the fix was simple, I now need to add some error checking into the way in which the bot handles incoming messages and reponses from Domoticz, once I have had a chance to do this I will upload a new version.
1) is one of the errors I should catch, 2) will need a little more thought.G3rard wrote:Maybe you can also have a look into 2 minor issues I have seen:
1) when sending only the command "/On" dtgbot gets in a loop and no other messages are accepted anymore
2) when sending "/On Lamp (kitchen)" this is interpreted as "/On Lamp kitchen". So the brackets are removed from the device name, meaning you can't switch a device with brackets in the name.
Code: Select all
function send_msg(SendTo, Message,MessageId)
print("sendto: "..SendTo)
print("telegramchatid: "..TelegramChatId)
if (SendTo == TelegramChatId) then --user/group is the same as defined in domoticzdata.sh
print(telegram_url..'sendMessage?timeout=60&chat_id='..SendTo..'&reply_to_message_id='..MessageId..'&text='..url_encode(Message))
response, status = https.request(telegram_url..'sendMessage?chat_id='..SendTo..'&reply_to_message_id='..MessageId..'&text='..url_encode(Message))
else --unknown user/group, don't send the message, send a warning to the user/group defined in domoticzdata.sh
text_unkown_user = "Unknown user "..SendTo.." using Domoticz bot"
print(text_unkown_user)
response, status = https.request(telegram_url..'sendMessage?chat_id='..TelegramChatId..'&reply_to_message_id='..MessageId..'&text='..text_unkown_user)
end
-- response, status = https.request(telegram_url..'sendMessage?chat_id='..SendTo..'&text=hjk')
print(status)
return
end
Code: Select all
print (os.date ("%a %d-%m-%Y %H:%M:%S"))
I haven't quite worked out the security model of the bots, I guess if you know the name of a bot then you can interact with it.G3rard wrote:@simonrg, I have changed the function send_msg in dtgbot.lua a little bit so the bot only sends messages to the chat id which is defined in DomoticzData.sh.
........
I have also added somelines in dtgbot.lua so it is easier to see when a request is handled.Code: Select all
print (os.date ("%a %d-%m-%Y %H:%M:%S"))
I think you can add any bot (did a search on Domoticz and then you find several bots) and that's not handy for Domoticz bots.simonrg wrote: I haven't quite worked out the security model of the bots, I guess if you know the name of a bot then you can interact with it.
The idea is to either add something into dtgbot.cfg that defines a list of acceptable ids or put a variable in Domoticz.
I need to have a think about logging, certainly a few times and dates would be a good idea.
Thanks.
Brutus, could be easy could be difficult, it depends on whether you have the Lua libraries available for Windows or not. If yes easy, if no then why not move to Linux. So you need to find socket, ssl and json Lua libraries for Windows. SimonBrutus wrote:Is it possible to get this some how working on Windows?
My doorbel (picture and message) already functions with a LUA and curl using the Telegram Bot. Already happy with that but chatting to Domoticz and receiving info back would be very nice
Users browsing this forum: No registered users and 1 guest