Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect survey schedules before sending SMS #2380

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

mverzilli
Copy link
Contributor

@mverzilli mverzilli commented Mar 5, 2025

Fixes #2283

The fix involves adding not_before and not_after fields to ChannelBroker.ask (aka, sms, btw why don't we rename this??), and honoring them (it was only sent with ChannelBroker.setup (aka, 'ivr', ditto).

The way to honor those fields involves:

  • Making sure they get also saved in the queue (previously only for IVR, nil for SMS)
  • Add expiration checks for SMS when ChannelBroker dequeues
  • Mark contact attempts as expired accordingly (so it gets picked up the next day)

Pending work:

  • Make it work
  • Make it nice (aka refactor)
  • Future proof (add some more test cases)
  • Update docs with new behaviors

@@ -36,8 +36,8 @@ defmodule Ask.Runtime.ChannelBroker do
call(channel_id, {:has_delivery_confirmation?})
end

def ask(channel_id, channel_type, respondent, token, reply) do
cast(channel_id, {:ask, channel_type, respondent, token, reply})
def ask(channel_id, channel_type, respondent, token, reply, not_before \\ nil, not_after \\ nil) do
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tempted to refactor so that nil's aren't accepted, but I wonder if there are other parts of Surveda where a schedule is really optional

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, was about to notice the same thing, but didn't want to nitpick too much.

The only Surveda use case without a schedule may be the questionnaire simulator, but even then I think we're setting up a whole survey with a fake/"always on" schedule.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the simulator came to mind. I can do it then. Let's pray that test coverage is enough :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm, I just noticed ask is also used for mobile web mode, and in that one we don't care about schedules

Copy link
Member

@matiasgarciaisaia matiasgarciaisaia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 👍

@@ -36,8 +36,8 @@ defmodule Ask.Runtime.ChannelBroker do
call(channel_id, {:has_delivery_confirmation?})
end

def ask(channel_id, channel_type, respondent, token, reply) do
cast(channel_id, {:ask, channel_type, respondent, token, reply})
def ask(channel_id, channel_type, respondent, token, reply, not_before \\ nil, not_after \\ nil) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, was about to notice the same thing, but didn't want to nitpick too much.

The only Surveda use case without a schedule may be the questionnaire simulator, but even then I think we're setting up a whole survey with a fake/"always on" schedule.

@@ -69,9 +69,9 @@ defmodule Ask.Runtime.ChannelBrokerStateTest do
mock_time(now)

State.new(0, "sms", %{})
|> State.queue_contact({%{id: 2, disposition: :queued}, "secret", []}, 5)
|> State.queue_contact({%{id: 2, disposition: :queued}, "secret", [], nil, nil}, 5)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we set non-nil times here, so we don't add coverage for a case we don't want to support?

Enum.at(respondents, 4)
]

# All respondents should be in broker queue, but only the first one contacted
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where's Surveda guaranteeing this? We activate respondents with a not_before in the following minute, too, so I think there's a good chance of contacting both respondents 3 and 4 here when the broker runs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an outdated comment from a previous iteration on this test, it's actually not true even in the context of this test. Will fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Respect Survey schedule when sending SMS messages
2 participants