0

If I create a Twilio conversation like so...

conversation = client.conversations.conversations.create(
  friendly_name='foo', 
  unique_name='foo',
  timers_closed='PT24H'
)

...after 24 hours the conversation state is set to 'closed', as expected. However, the webhook associated with conversation state change (onConversationStateUpdated) is not getting called (I think?).

The docs seem to suggest the webhook is not called, but the phrasing is so odd and that behavior seems so odd, that I don't completely believe it. The docs say:

Currently, you can only control the post-webhook onConversationStateUpdated via the REST API.

Am I correct in my reading? Is a webhook not triggered? Why on earth would I not want a webhook triggered here? What's the correct way to detect that a conversation state has changed then?

Chris W.
  • 37,583
  • 36
  • 99
  • 136

1 Answers1

0

There are three different "levels" of webhooks: Global-scoped and Service-scoped and Conversation-scoped.

Twilio support claims that onConversationStateUpdated event should fire for all levels of webhooks. However, I swear it will not fire for me on the global webhook.

My solution ended up being creating a webhook for each conversation which I start with twilio. e.g.,

    client = get_my_twilio_client(...)
    convo = client.conversations.conversations.create(
        friendly_name='Foo',
        timers_closed=DURATION_24HRS,
    )
    convo.webhooks.create(
        target="webhook",
        configuration_filters=["onConversationStateUpdated"],
        configuration_url=get_my_webhook_url(),
    )
Chris W.
  • 37,583
  • 36
  • 99
  • 136