Chatbot plugin

Posted on
Wed Jan 27, 2016 5:27 pm
gazally offline
Posts: 27
Joined: Jan 18, 2016
Location: Bigfoot country

Chatbot plugin

The first version of my Messages app plugin would try to find and execute Action Groups with names matching incoming messages. I got tired of the limitations of that approach quickly and decided that what I really needed was two plugins. One plugin focused on sending and receiving messages, and another plugin to connect incoming messages to Python scripts that could both make things happen in Indigo and figure out what response to send back. This is the second plugin, which with a little bit of setup to coordinate it with whatever message delivery service you are using, will turn Indigo into a chatbot.

There's no shortage of open source software around for building chatbots, but I couldn't find anything that was exactly what I was looking for, so I collected various ideas I liked from the chatbot world and wrote my own little chatbot engine. It will import a directory full of Python files, where the decorator syntax is used to associate messages to be matched with methods to run, and the methods can work with Indigo just like other Python scripts, and then return text responses to be sent back to the user.

The plugin defines devices called "Chatbot Responders" and a "Get Chatbot Response" action which takes a message, gets a response and stashes it in device states along with the original message, the sender's name, and three generic text fields which you can use to save address information to help you deliver the return message.

Example scripts, incomplete documentation and a download link can be found here: https://github.com/gazally/indigo-chatbot

Posted on
Sat Apr 02, 2016 10:08 am
dz1rfj offline
Posts: 136
Joined: Mar 13, 2016

Re: Chatbot plugin

New to Indigo, and no python experience at all...

Will this plugin allow me somehow setup my mac to get a text message, and to have someone text a command to my mac that will trigger an indigo device?

Thanks

Thanks
-Brian

Posted on
Sat Apr 02, 2016 11:40 am
gazally offline
Posts: 27
Joined: Jan 18, 2016
Location: Bigfoot country

Re: Chatbot plugin

My Messages plugin is the one you want if the person texting your mac has an iPhone. The Messages plugin also works with Google Hangouts from any kind of phone. If the person texting your mac can only send SMS messages, there is a Google Voice plugin, forum link here: http://forums.indigodomo.com/viewtopic.php?f=65&t=7438. With either one of those plugins you can set up a trigger in Indigo that will run a command when a message is received.

The Chatbot plugin is for people with some Python experience who would like to build more complex natural language interaction. For example:

Indigo: The garage door is open. Should I remind you to close it in a bit?
You: no
Indigo: Ok. But if it gets late or dark and it's still open I'll tell you
Indigo: The garage door is still open
You: Close it
Indigo:Ok pushing the close button now
Indigo:The garage is closed

Posted on
Sat Apr 02, 2016 12:06 pm
gazally offline
Posts: 27
Joined: Jan 18, 2016
Location: Bigfoot country

Re: Chatbot plugin

I've just uploaded a new version, v0.3.1, which fixes a problem this plugin had with Indigo v6.1.7. In this plugin I had set up the Python standard library logging module to use self.debugLog and self.errorLog. In Indigo 6.17 they changed self.debugLog and self.errorLog to use the Python standard library logging module. Result: recursion to the Python limit and a very large number of copies of each log message.

Also added to this version are two new menu commands. One will allow you to converse with the chatbot engine by typing into a Terminal window, so you don't have to test your scripts by going through a messaging app. The other will open a Python interpreter with access to the plugin's internal data structures, which might be helpful for script debugging. See the README at the download link above for details.

Posted on
Sat Apr 02, 2016 4:04 pm
dz1rfj offline
Posts: 136
Joined: Mar 13, 2016

Re: Chatbot plugin

That is AWESOME.

I had to create two triggers, one that looks at ANY message that is new, and I mark it as READ, and then, the trigger I wanted, which gets the message Fire Pit as a test to turn on the outside lights near the fire pit. When the Fire pit string lights turn on, that trigger also marks the message as read. seems to solve my issues.

I also noticed if I text Fire Pit, and Fire Pit again, the 2nd is ignored, but if I text Fire Pit and any random text, then Fire Pit again, it works as expected during testing.

Have I gone about it in a straight forward manner, or is there a better way?

Thanks!

Thanks
-Brian

Posted on
Sat Apr 02, 2016 10:37 pm
gazally offline
Posts: 27
Joined: Jan 18, 2016
Location: Bigfoot country

Re: Chatbot plugin

Yes I think you are on the right track. Two triggers are necessary, but only one of them should be marking messages read, the one that is looking at every new message. A one second delay on the mark read action can help if messages are getting lost. Indigo doesn't necessarily run your actions in the order you think it's going to.

Is your Fire Pit trigger set to go off when the device status becomes New? As opposed to when the message becomes Fire Pit?

Posted on
Sun Apr 03, 2016 7:08 pm
dz1rfj offline
Posts: 136
Joined: Mar 13, 2016

Re: Chatbot plugin

gazally wrote:
Is your Fire Pit trigger set to go off when the device status becomes New? As opposed to when the message becomes Fire Pit?


No, then the Fire Pit lights would turn on all the time, so that trigger only fires if Fire Pit is sent to my phone.

Thanks
-Brian

Posted on
Mon Apr 04, 2016 11:30 am
gazally offline
Posts: 27
Joined: Jan 18, 2016
Location: Bigfoot country

Re: Chatbot plugin

Try this: change your firepit trigger to react when the Message device state becomes New, and then go to the Condition tab of the trigger, select "If conditions match rules", and change the rule to If device/your message device/Last Message Received/is equal to/Fire Pit. That should fix the problem where the second fire pit message doesn't fire the trigger.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests

cron