HTTP 409 error: Unable to delete record

Posted on
Mon May 17, 2021 3:24 pm
jltnol offline
Posts: 989
Joined: Oct 15, 2013

HTTP 409 error: Unable to delete record

So while I think I have this mostly sorted out, I keep getting these error messages:

Note that Indigo is getting the notice from Twilio, and later, the trigger does fire, but not so in the second example.

I have the plugin set to the default of polling every 5 minutes... and while I'm not cascading messages to Indigo, is there a "time out" period where subsequent messages won't be acted upon? Something more than 5-10 seconds or so?

Code: Select all
WebServer                       request to set variable "twilio_ping" value to "true"
   Trigger                         **Get Twilo
   Twilio Error                    checkMessages: twilioClient.messages.delete() error: HTTP 409 error: Unable to delete record: Cannot delete message because delivery has not been completed.
Traceback (most recent call last):
  File "plugin.py", line 433, in checkMessages
    self.twilioClient.messages(message.sid).delete()
  File "/Library/Application Support/Perceptive Automation/Indigo 7.5/Plugins/Twilio.indigoPlugin/Contents/Server Plugin/twilio/rest/api/v2010/account/message/__init__.py", line 326, in delete
    return self._version.delete('delete', self._uri)
  File "/Library/Application Support/Perceptive Automation/Indigo 7.5/Plugins/Twilio.indigoPlugin/Contents/Server Plugin/twilio/base/version.py", line 124, in delete
    raise self.exception(method, uri, response, 'Unable to delete record')
TwilioRestException: HTTP 409 error: Unable to delete record: Cannot delete message because delivery has not been completed.
   Trigger                         Twilio Home Kitchen Test


In this case, which was 6 minutes later, Indigo is getting the message, but the trigger( a simple light toggle) is not acted upon for some reason. The **Get Twilo (delayed action) resets the variable... (just didn't include it in the 1st example..

Code: Select all
WebServer                       request to set variable "twilio_ping" value to "true"
   Trigger                         **Get Twilo
   Twilio Error                    checkMessages: twilioClient.messages.delete() error: HTTP 409 error: Unable to delete record: Cannot delete message because delivery has not been completed.
Traceback (most recent call last):
  File "plugin.py", line 433, in checkMessages
    self.twilioClient.messages(message.sid).delete()
  File "/Library/Application Support/Perceptive Automation/Indigo 7.5/Plugins/Twilio.indigoPlugin/Contents/Server Plugin/twilio/rest/api/v2010/account/message/__init__.py", line 326, in delete
    return self._version.delete('delete', self._uri)
  File "/Library/Application Support/Perceptive Automation/Indigo 7.5/Plugins/Twilio.indigoPlugin/Contents/Server Plugin/twilio/base/version.py", line 124, in delete
    raise self.exception(method, uri, response, 'Unable to delete record')
TwilioRestException: HTTP 409 error: Unable to delete record: Cannot delete message because delivery has not been completed.
   Schedule                        **Get Twilo (delayed action)

Posted on
Mon May 17, 2021 3:27 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: HTTP 409 error: Unable to delete record

Show what's in the **Get Twilio trigger's actions.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon May 17, 2021 4:57 pm
jltnol offline
Posts: 989
Joined: Oct 15, 2013

Re:HTTP 409 error: Unable to delete record

The Trigger fires when the Twilio_ping variable changes to True.

The actions are
1. Check for Messages (Twilio Actions)
2. Modify Variable (to something other than True). this has a delay of :04 seconds.


And there is a 2nd Trigger that fires when a Twilio Event / SMS Message received, with a condition that actually checks for message text, and then performs an action... in my case, just toggle a light on/ off

Posted on
Mon May 17, 2021 6:03 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: HTTP 409 error: Unable to delete record

If you're using Immediate Notifications (ie the webhook), then there's no reason to be polling at all. Set that to 0 in the config dialog.

In my setup, I have no delay between the check messages action and reseting the variable.

In the Twilio dashboard, do you have any other actions specified for inbound SMS messages? Do you have some action specified in case of primary handler failure?

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon May 17, 2021 9:26 pm
jltnol offline
Posts: 989
Joined: Oct 15, 2013

Re: HTTP 409 error: Unable to delete record

Ill make the changes in the polling time as well as the variable reset and see what happens.. I have no other configs in Twilio.

Thanks for your help.

Posted on
Mon May 17, 2021 10:10 pm
jltnol offline
Posts: 989
Joined: Oct 15, 2013

Re: HTTP 409 error: Unable to delete record

I've changed the Trigger Action to a lamp that doesn't have any other Indigo processes attached... whether it turns on or off, nothing else in Indigo happens. Still getting. a lot of error messages, and still sometimes the trigger fires and sometimes it doesn't...

So I turned on debugging and noticed that some entries have this:
Twilio Debug checkMessages: Message from +15047234449, to: +19852383530, direction: inbound, date_sent: 'None'

When that happens, I get the error messages and the trigger doesn't fire. So I'm just wondering if Twilio has some kind of "time out" that prevents things from happening so quickly.

Here is the whole event log sequence:
Code: Select all
May 17, 2021 at 11:00:53 PM
   WebServer                       request to set variable "twilio_ping" value to "true"
   Trigger                         **Get Twilo
   Twilio Debug                    checkMessages: Message from +15047234449, to: +19852383530, direction: inbound, date_sent: '2021-05-18 04:00:54+00:00'
   Twilio Debug                    Checking Trigger Twilio Home from phone (20985967), Type: messageReceived
   Twilio Debug                    Checking Trigger Twilio Home Kitchen Test (1630240852), Type: messageReceived
   Trigger                         Twilio Home Innovelli Test
   Twilio Debug                    Checking Trigger Mail -Reset  TWILo verion (1760923517), Type: messageReceived
   Z-Wave                          sent "Invonelli" off
   Twilio Debug                    checkMessages: Message from +1504734449, to: +19852383530, direction: inbound, date_sent: '2021-05-18 03:55:35+00:00'
   Twilio Debug                    Checking Trigger Twilio Home from phone (20985967), Type: messageReceived
   Twilio Debug                    Checking Trigger Twilio Home Kitchen Test (1630240852), Type: messageReceived
   Trigger                         Twilio Home Innovelli Test
   Twilio Debug                    Checking Trigger Mail -Reset  TWILo verion (1760923517), Type: messageReceived
   Z-Wave                          sent "Invonelli" on
   Twilio Debug                    checkMessages: Done
   Z-Wave                          received "Invonelli" power load to 39.0 W
   Z-Wave                          received "Invonelli" energy total to 0.004 kWh

May 17, 2021 at 11:01:30 PM
   WebServer                       request to set variable "twilio_ping" value to "true"
   Trigger                         **Get Twilo
   Twilio Debug                    checkMessages: Message from +15047234449, to: +19852383530, direction: inbound, date_sent: 'None'
   Twilio Error                    checkMessages: twilioClient.messages.delete() error: HTTP 409 error: Unable to delete record: Cannot delete message because delivery has not been completed.
Traceback (most recent call last):
  File "plugin.py", line 433, in checkMessages
    self.twilioClient.messages(message.sid).delete()
  File "/Library/Application Support/Perceptive Automation/Indigo 7.5/Plugins/Twilio.indigoPlugin/Contents/Server Plugin/twilio/rest/api/v2010/account/message/__init__.py", line 326, in delete
    return self._version.delete('delete', self._uri)
  File "/Library/Application Support/Perceptive Automation/Indigo 7.5/Plugins/Twilio.indigoPlugin/Contents/Server Plugin/twilio/base/version.py", line 124, in delete
    raise self.exception(method, uri, response, 'Unable to delete record')
TwilioRestException: HTTP 409 error: Unable to delete record: Cannot delete message because delivery has not been completed.
   Twilio Debug                    checkMessages: Done

May 17, 2021 at 11:02:18 PM
   Z-Wave                          received "Invonelli" energy total to 0.005 kWh
   Z-Wave                          received "Invonelli" power load to 39.6 W

Posted on
Tue May 18, 2021 8:11 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: HTTP 409 error: Unable to delete record

I've actually been able to reproduce this now with my setup. Something changed on the Twilio server side, because I never saw this before. I'll investigate.

Now being tracked in GitHub: https://github.com/FlyingDiver/Indigo-Twilio/issues/7

Split the forum posts into new thread.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Fri Jun 11, 2021 11:35 am
jltnol offline
Posts: 989
Joined: Oct 15, 2013

Re: HTTP 409 error: Unable to delete record

Hey there.

Just curious if you have an idea of whether this is something you'll be able to get fixed or not.
Really not important for me one may or the other as your plugin and Twilio have solved a host of issues for me...I'm just more just curious.. :)

I've been able to get Twilio to work like an answer machine for me, a great thing. This involved a Stuio Flow, and was wondering if it might be possible to create a Studio Flow to do what the web hook was designed to do.. ? OTOH, I can easily see how incorporating a version of the web hook into a Studio Flow could easily result in the same error messages...

This is way past my pay grade, so I maybe talking nonsense..

Posted on
Fri Jun 11, 2021 12:07 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: HTTP 409 error: Unable to delete record

Haven't had a chance to look into that error, but I will.

I actually did some work with Studio Flows, mainly to see if I could use a Flow to get some input from a caller, then report that to Indigo. See https://github.com/FlyingDiver/Indigo-T ... o-Flow-API

But in any case, you need to use something on the Indigo side to receive the webhook from the Twilio server. That could be the HTTPd plugin, or the IWS plugin, or directly to the reflector (in the next Indigo release).

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Fri Jun 11, 2021 7:26 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: HTTP 409 error: Unable to delete record

So I think I fixed the 409 error exception, but not the underlying cause. It looks like the Twilio servers are firing the webhook before all the messages are fully processed. I get the new message "object" back from the server, but it's not complete. No date_sent field, for instance. And attempting to process and delete it at that time fails. For now, the plugin won't even attempt to process it, but since the webhook has already fired, it will not be re-fetched and processed until another webhook fires, or it polls (interval set in plugin config).

I have a ticket open with Twilio to see why the webhook is firing early.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Tue Jun 15, 2021 5:05 pm
hamw offline
Posts: 1212
Joined: Mar 31, 2008

Re: HTTP 409 error: Unable to delete record

Same problem here. Thanks for looking into it!

Posted on
Tue Jun 15, 2021 5:17 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: HTTP 409 error: Unable to delete record

You can fix it by adding a delay to the action to poll for the messages. 3-5 seconds should be enough.


Sent from my iPhone using Tapatalk

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Wed Jun 16, 2021 9:26 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: HTTP 409 error: Unable to delete record

FWIW, I'm going back and forth with Twilio developer support on this issue. I can't seem to get them to understand that they're sending the webhook too soon. They keep telling me that "carrier delays are out of their control". Sigh.

But as I posted last night, it's actually a trivial fix in Indigo. Just put a delay on the poll action in the trigger.
Attachments
Screen Shot 2021-06-16 at 11.26.00 AM.png
Screen Shot 2021-06-16 at 11.26.00 AM.png (608.84 KiB) Viewed 9946 times

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Wed Jun 16, 2021 10:50 am
jltnol offline
Posts: 989
Joined: Oct 15, 2013

Re: HTTP 409 error: Unable to delete record

So I've tried. your fix but incoming messages are still not being acted upon.

I have 3 triggers, one fires when the variable is changed to 'true'. Twilio is successfully notifying Indigo of a message as the variable is changing to 'true'. From there, I've added the 3 second delay before the plugin checks for messages, and a 7 second delay before the variable is changed to something other than 'true'. This part seems to work fine. On the Twilio website, If I'm fast enough with the refresh button, I can see the text message come in from my cell # before it is deleted.

I have 2 other triggers that check for incoming text. It appears that there are 2 ways to do this:

The first is just have the trigger check for any incoming text message, and set a condition in the trigger to check what the text is, and then perform an action.
The second way is to be to have the trigger itself check for Pattern Match in SMS Message, and then perform an action.

As it turns out, I have one of each type setup, but neither are working. With the plugin set to Debug Message, when I send a text to my Twilio #, I can see that the variable is being changed to true, and both triggers are being evaluated, but again, nothing happens

So I'm curious about 2 things.. the first being between the 2 methods I've outlined above, is there a preference for how to check for incoming messages? Any reason why one might be better than the other?

And the second is, for the triggers that check for certain text, do they go back to the Twilio website and check for messages, or do they look for that incoming text cached in the plugin? I'm assuming the latter.

I do get a bit confused about "Message From" vs. "Message To", have decided it should be Message To, but have tried both, and still triggers aren't firing.

I understand you are waiting on Twilio for more info, and as I've mentioned before, this is the least of my worries with the plugin. 99% of what I do is send message out from Indigo, which works perfectly. And I'm half-way assuming I'm making an elemental error in how I have the Triggers evaluate incoming text, but don't see another way to do so.

So just curious about the questions above and if you see anything that I'm doing wrong in trying to evaluate incoming text messages...

THANKS...

Posted on
Wed Jun 16, 2021 11:11 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: HTTP 409 error: Unable to delete record

So logically, there are two classes of triggers that you're dealing with. The first is the webhook trigger, which is used to cause the Twilio plugin to poll for new messages. It's totally optional, and is just a way of doing the poll on-demand instead of on a schedule. I've also changed my setup to not even use a variable. Now the webhook just looks like:
Code: Select all
http://username:password@ddns.name:5555/setvar

Turns out that Twilio by default includes a whole bunch of info with the webhook call, so I now skip the variable and use the HTTPd-2 device states to trigger the poll, like this:
Screen Shot 2021-06-16 at 1.08.11 PM.png
Screen Shot 2021-06-16 at 1.08.11 PM.png (387.91 KiB) Viewed 9929 times

The device states (after an http request from Twilio) look like:
Screen Shot 2021-06-16 at 1.07.34 PM.png
Screen Shot 2021-06-16 at 1.07.34 PM.png (119.33 KiB) Viewed 9929 times

Using MessageSid instead of body would be even better.

That's all that's needed to get the plugin to poll for new messages.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Who is online

Users browsing this forum: No registered users and 2 guests