diff --git a/corehq/apps/commtrack/sms.py b/corehq/apps/commtrack/sms.py index ee08aa11140a..136dcacf8302 100644 --- a/corehq/apps/commtrack/sms.py +++ b/corehq/apps/commtrack/sms.py @@ -21,7 +21,7 @@ from corehq.apps.domain.models import Domain from corehq.apps.products.models import SQLProduct from corehq.apps.receiverwrapper.util import submit_form_locally -from corehq.apps.sms.api import MessageMetadata, send_sms_to_verified_number +from corehq.apps.sms.api import MessageMetadata, send_message_to_verified_number from corehq.apps.users.models import CouchUser from corehq.form_processor.interfaces.supply import SupplyInterface from corehq.form_processor.parsers.ledgers.helpers import ( @@ -50,7 +50,7 @@ def handle(verified_contact, text, msg): except Exception as e: if settings.UNIT_TESTING or settings.DEBUG: raise - send_sms_to_verified_number(verified_contact, 'problem with stock report: %s' % str(e)) + send_message_to_verified_number(verified_contact, 'problem with stock report: %s' % str(e)) return True process(domain_obj.name, data) @@ -372,4 +372,4 @@ def summarize_action(action, txs): ' '.join(sorted(summarize_action(a, txs) for a, txs in tx_by_action.items())) ) - send_sms_to_verified_number(v, msg, metadata=metadata) + send_message_to_verified_number(v, msg, metadata=metadata) diff --git a/corehq/apps/sms/filters.py b/corehq/apps/sms/filters.py index c681f8babd44..b83e134e7797 100644 --- a/corehq/apps/sms/filters.py +++ b/corehq/apps/sms/filters.py @@ -80,6 +80,7 @@ def options(self): (MessagingEvent.CONTENT_SMS_CALLBACK, gettext_noop('SMS Callback')), (MessagingEvent.CONTENT_SMS, gettext_noop('Other SMS')), (MessagingEvent.CONTENT_EMAIL, gettext_noop('Email')), + (MessagingEvent.CONTENT_CONNECT, gettext_noop('Connect Message')), ] diff --git a/corehq/apps/sms/handlers/fallback.py b/corehq/apps/sms/handlers/fallback.py index fc6413c0f624..01ad318199ce 100644 --- a/corehq/apps/sms/handlers/fallback.py +++ b/corehq/apps/sms/handlers/fallback.py @@ -2,7 +2,7 @@ from corehq.apps.sms.api import ( MessageMetadata, add_msg_tags, - send_sms_to_verified_number, + send_message_to_verified_number, ) from corehq.apps.sms.models import WORKFLOW_DEFAULT, MessagingEvent @@ -26,7 +26,7 @@ def fallback_handler(verified_number, text, msg): outbound_meta = MessageMetadata(workflow=WORKFLOW_DEFAULT, location_id=msg.location_id, messaging_subevent_id=outbound_subevent.pk) - send_sms_to_verified_number(verified_number, domain_obj.default_sms_response, + send_message_to_verified_number(verified_number, domain_obj.default_sms_response, metadata=outbound_meta) outbound_subevent.completed() diff --git a/corehq/apps/sms/handlers/form_session.py b/corehq/apps/sms/handlers/form_session.py index 931f859ba51f..fd664ec5a878 100644 --- a/corehq/apps/sms/handlers/form_session.py +++ b/corehq/apps/sms/handlers/form_session.py @@ -9,7 +9,7 @@ MessageMetadata, add_msg_tags, log_sms_exception, - send_sms_to_verified_number, + send_message_to_verified_number, ) from corehq.apps.sms.messages import ( MSG_CHOICE_OUT_OF_RANGE, @@ -59,7 +59,7 @@ def form_session_handler(verified_number, text, msg): "message_id": msg.couch_id }) session.mark_completed(False) # this will also release the channel - send_sms_to_verified_number( + send_message_to_verified_number( verified_number, get_message(MSG_GENERIC_ERROR, verified_number) ) return True @@ -77,7 +77,7 @@ def form_session_handler(verified_number, text, msg): verified_number.domain, verified_number.owner_id ) if multiple: - send_sms_to_verified_number(verified_number, get_message(MSG_GENERIC_ERROR, verified_number)) + send_message_to_verified_number(verified_number, get_message(MSG_GENERIC_ERROR, verified_number)) return True if session: @@ -102,7 +102,7 @@ def form_session_handler(verified_number, text, msg): except Exception: # Catch any touchforms errors log_sms_exception(msg) - send_sms_to_verified_number(verified_number, get_message(MSG_TOUCHFORMS_DOWN, verified_number)) + send_message_to_verified_number(verified_number, get_message(MSG_TOUCHFORMS_DOWN, verified_number)) return True else: return False @@ -152,12 +152,12 @@ def answer_next_question(verified_number, text, msg, session, subevent_id): events = get_events_from_responses(responses) if len(text_responses) > 0: response_text = format_message_list(text_responses) - send_sms_to_verified_number(verified_number, response_text, + send_message_to_verified_number(verified_number, response_text, metadata=outbound_metadata, events=events) else: mark_as_invalid_response(msg) response_text = "%s %s" % (error_msg, event.text_prompt) - send_sms_to_verified_number(verified_number, response_text, + send_message_to_verified_number(verified_number, response_text, metadata=outbound_metadata, events=[event]) diff --git a/corehq/apps/sms/handlers/keyword.py b/corehq/apps/sms/handlers/keyword.py index 595135ea3944..5e3c41f45614 100644 --- a/corehq/apps/sms/handlers/keyword.py +++ b/corehq/apps/sms/handlers/keyword.py @@ -13,7 +13,7 @@ from corehq.apps.sms.api import ( MessageMetadata, add_msg_tags, - send_sms_to_verified_number, + send_message_to_verified_number, ) from corehq.apps.sms.handlers.form_session import validate_answer from corehq.apps.sms.messages import ( @@ -107,10 +107,10 @@ def global_keyword_start(verified_number, text, msg, text_words, open_sessions): process_survey_keyword_actions(verified_number, k, text[6:].strip(), msg) else: message = get_message(MSG_KEYWORD_NOT_FOUND, verified_number, (keyword,)) - send_sms_to_verified_number(verified_number, message, metadata=outbound_metadata) + send_message_to_verified_number(verified_number, message, metadata=outbound_metadata) else: message = get_message(MSG_START_KEYWORD_USAGE, verified_number, (text_words[0],)) - send_sms_to_verified_number(verified_number, message, metadata=outbound_metadata) + send_message_to_verified_number(verified_number, message, metadata=outbound_metadata) return True @@ -130,14 +130,14 @@ def global_keyword_current(verified_number, text, msg, text_words, open_sessions resp = FormplayerInterface(session.session_id, verified_number.domain).current_question() - send_sms_to_verified_number(verified_number, resp.event.text_prompt, + send_message_to_verified_number(verified_number, resp.event.text_prompt, metadata=outbound_metadata, events=[resp.event]) return True def global_keyword_unknown(verified_number, text, msg, text_words, open_sessions): message = get_message(MSG_UNKNOWN_GLOBAL_KEYWORD, verified_number, (text_words[0],)) - send_sms_to_verified_number(verified_number, message) + send_message_to_verified_number(verified_number, message) return True @@ -469,7 +469,7 @@ def clean_up_and_send_response(msg, contact, session, error_occurred, error_msg, contact.doc_type, contact.get_id) metadata.messaging_subevent_id = response_subevent.pk - send_sms_to_verified_number(verified_number, error_msg, metadata=metadata) + send_message_to_verified_number(verified_number, error_msg, metadata=metadata) if response_subevent: response_subevent.completed() @@ -560,7 +560,7 @@ def send_keyword_response(vn, message_id, logged_event): messaging_subevent_id=subevent.pk, ) message = get_message(message_id, vn) - send_sms_to_verified_number(vn, message, metadata=metadata) + send_message_to_verified_number(vn, message, metadata=metadata) subevent.completed() diff --git a/corehq/apps/sms/tests/opt_tests.py b/corehq/apps/sms/tests/opt_tests.py index f1c6855a9afa..fd4482348ff3 100644 --- a/corehq/apps/sms/tests/opt_tests.py +++ b/corehq/apps/sms/tests/opt_tests.py @@ -6,7 +6,7 @@ from corehq.apps.domain.models import Domain from corehq.messaging.pillow import get_case_messaging_sync_pillow from corehq.messaging.smsbackends.test.models import SQLTestSMSBackend -from corehq.apps.sms.api import incoming, send_sms_to_verified_number +from corehq.apps.sms.api import incoming, send_message_to_verified_number from corehq.apps.sms.messages import MSG_OPTED_IN, MSG_OPTED_OUT, get_message from corehq.apps.sms.models import SMS, PhoneBlacklist, PhoneNumber, SQLMobileBackendMapping, SQLMobileBackend from corehq.apps.sms.tests.util import ( @@ -108,7 +108,7 @@ def test_sending_to_opted_out_number(self): v = PhoneNumber.get_two_way_number('99912345678') self.assertIsNotNone(v) - send_sms_to_verified_number(v, 'hello') + send_message_to_verified_number(v, 'hello') sms = self.get_last_sms('+99912345678') self.assertEqual(sms.direction, 'O') self.assertEqual(sms.text, 'hello') @@ -118,7 +118,7 @@ def test_sending_to_opted_out_number(self): phone_number = PhoneBlacklist.objects.get(phone_number='99912345678') self.assertFalse(phone_number.send_sms) - send_sms_to_verified_number(v, 'hello') + send_message_to_verified_number(v, 'hello') sms = self.get_last_sms('+99912345678') self.assertEqual(sms.direction, 'O') self.assertEqual(sms.text, 'hello') @@ -130,7 +130,7 @@ def test_sending_to_opted_out_number(self): phone_number = PhoneBlacklist.objects.get(phone_number='99912345678') self.assertTrue(phone_number.send_sms) - send_sms_to_verified_number(v, 'hello') + send_message_to_verified_number(v, 'hello') sms = self.get_last_sms('+99912345678') self.assertEqual(sms.direction, 'O') self.assertEqual(sms.text, 'hello') @@ -144,7 +144,7 @@ def test_custom_opt_keywords(self): v = PhoneNumber.get_two_way_number('19912345678') self.assertIsNotNone(v) - send_sms_to_verified_number(v, 'hello') + send_message_to_verified_number(v, 'hello') sms = self.get_last_sms('+19912345678') self.assertEqual(sms.direction, 'O') self.assertEqual(sms.text, 'hello') @@ -154,7 +154,7 @@ def test_custom_opt_keywords(self): phone_number = PhoneBlacklist.objects.get(phone_number='19912345678') self.assertFalse(phone_number.send_sms) - send_sms_to_verified_number(v, 'hello') + send_message_to_verified_number(v, 'hello') sms = self.get_last_sms('+19912345678') self.assertEqual(sms.direction, 'O') self.assertEqual(sms.text, 'hello') @@ -166,7 +166,7 @@ def test_custom_opt_keywords(self): phone_number = PhoneBlacklist.objects.get(phone_number='19912345678') self.assertTrue(phone_number.send_sms) - send_sms_to_verified_number(v, 'hello') + send_message_to_verified_number(v, 'hello') sms = self.get_last_sms('+19912345678') self.assertEqual(sms.direction, 'O') self.assertEqual(sms.text, 'hello') diff --git a/corehq/apps/sms/tests/test_backends.py b/corehq/apps/sms/tests/test_backends.py index 8665c5b42f67..94a5a696ed49 100644 --- a/corehq/apps/sms/tests/test_backends.py +++ b/corehq/apps/sms/tests/test_backends.py @@ -16,7 +16,7 @@ from corehq.apps.hqcase.utils import update_case from corehq.apps.sms.api import ( send_sms, - send_sms_to_verified_number, + send_message_to_verified_number, send_sms_with_backend, send_sms_with_backend_name, ) @@ -812,7 +812,7 @@ def __test_verified_number_with_map(self, contact): 'corehq.messaging.smsbackends.test.models.SQLTestSMSBackend.send', autospec=True ) as mock_send: - self.assertTrue(send_sms_to_verified_number(verified_number, 'Test for BACKEND2')) + self.assertTrue(send_message_to_verified_number(verified_number, 'Test for BACKEND2')) self.assertEqual(mock_send.call_count, 1) self.assertEqual(mock_send.call_args[0][0].pk, self.backend2.pk) @@ -823,7 +823,7 @@ def __test_verified_number_with_map(self, contact): 'corehq.messaging.smsbackends.test.models.SQLTestSMSBackend.send', autospec=True ) as mock_send: - self.assertTrue(send_sms_to_verified_number(verified_number, 'Test for BACKEND5')) + self.assertTrue(send_message_to_verified_number(verified_number, 'Test for BACKEND5')) self.assertEqual(mock_send.call_count, 1) self.assertEqual(mock_send.call_args[0][0].pk, self.backend5.pk) @@ -841,7 +841,7 @@ def __test_contact_level_backend(self, contact): 'corehq.messaging.smsbackends.test.models.SQLTestSMSBackend.send', autospec=True ) as mock_send: - self.assertTrue(send_sms_to_verified_number(verified_number, 'Test for domain BACKEND')) + self.assertTrue(send_message_to_verified_number(verified_number, 'Test for domain BACKEND')) self.assertEqual(mock_send.call_count, 1) self.assertEqual(mock_send.call_args[0][0].pk, self.backend8.pk) @@ -853,7 +853,7 @@ def __test_contact_level_backend(self, contact): 'corehq.messaging.smsbackends.test.models.SQLTestSMSBackend.send', autospec=True ) as mock_send: - self.assertTrue(send_sms_to_verified_number(verified_number, 'Test for shared domain BACKEND')) + self.assertTrue(send_message_to_verified_number(verified_number, 'Test for shared domain BACKEND')) self.assertEqual(mock_send.call_count, 1) self.assertEqual(mock_send.call_args[0][0].pk, self.backend9.pk) @@ -865,7 +865,7 @@ def __test_contact_level_backend(self, contact): 'corehq.messaging.smsbackends.test.models.SQLTestSMSBackend.send', autospec=True ) as mock_send: - self.assertTrue(send_sms_to_verified_number(verified_number, 'Test for global BACKEND')) + self.assertTrue(send_message_to_verified_number(verified_number, 'Test for global BACKEND')) self.assertEqual(mock_send.call_count, 1) self.assertEqual(mock_send.call_args[0][0].pk, self.backend10.pk) @@ -874,7 +874,7 @@ def __test_contact_level_backend(self, contact): self.backend10.save() with self.assertRaises(BadSMSConfigException): - send_sms_to_verified_number(verified_number, 'Test for unknown BACKEND') + send_message_to_verified_number(verified_number, 'Test for unknown BACKEND') def __test_send_sms_with_backend(self): with patch( diff --git a/corehq/apps/sms/tests/test_form_session_handler.py b/corehq/apps/sms/tests/test_form_session_handler.py index 565f698b3878..7b6ac72dce5b 100644 --- a/corehq/apps/sms/tests/test_form_session_handler.py +++ b/corehq/apps/sms/tests/test_form_session_handler.py @@ -222,7 +222,7 @@ def test_incoming_sms_linked_form_session__session_contact_matches_incoming(self self.assertEqual(session_info.session_id, session.session_id) @patch('corehq.apps.sms.handlers.form_session.answer_next_question', MagicMock(return_value=None)) - @patch('corehq.apps.sms.handlers.form_session.send_sms_to_verified_number', MagicMock(return_value=None)) + @patch('corehq.apps.sms.handlers.form_session.send_message_to_verified_number', MagicMock(return_value=None)) def test_incoming_sms_linked_form_session__session_contact_different_from_incoming(self): session = self._make_session(self.number2) self._claim_channel(session) diff --git a/corehq/apps/sms/verify.py b/corehq/apps/sms/verify.py index 03138035c3bf..dbce5cb74936 100644 --- a/corehq/apps/sms/verify.py +++ b/corehq/apps/sms/verify.py @@ -4,7 +4,7 @@ from corehq.apps.sms.api import ( MessageMetadata, send_sms, - send_sms_to_verified_number, + send_message_to_verified_number, ) from corehq.apps.sms.mixin import PhoneNumberInUseException, apply_leniency from corehq.apps.sms.models import ( @@ -135,7 +135,7 @@ def process_verification(verified_number, msg, verification_keywords=None, creat messages.MSG_VERIFICATION_SUCCESSFUL, verified_number=verified_number ) - send_sms_to_verified_number(verified_number, message, + send_message_to_verified_number(verified_number, message, metadata=MessageMetadata(messaging_subevent_id=subevent.pk)) subevent.completed() return True diff --git a/corehq/apps/sms/views.py b/corehq/apps/sms/views.py index f516c7d9f4c8..6af63867e372 100644 --- a/corehq/apps/sms/views.py +++ b/corehq/apps/sms/views.py @@ -77,7 +77,7 @@ get_inbound_phone_entry, incoming, send_sms, - send_sms_to_verified_number, + send_message_to_verified_number, send_sms_with_backend_name, ) from corehq.apps.sms.forms import ( @@ -543,7 +543,7 @@ def api_send_sms(request, domain): if backend_id is not None: success = send_sms_with_backend_name(domain, phone_number, text, backend_id, metadata) elif vn is not None: - success = send_sms_to_verified_number(vn, text, metadata) + success = send_message_to_verified_number(vn, text, metadata) else: success = send_sms(domain, None, phone_number, text, metadata) diff --git a/corehq/apps/smsforms/tasks.py b/corehq/apps/smsforms/tasks.py index c700b1766740..9be78d01daab 100644 --- a/corehq/apps/smsforms/tasks.py +++ b/corehq/apps/smsforms/tasks.py @@ -11,7 +11,7 @@ from corehq.apps.sms.api import ( MessageMetadata, send_sms, - send_sms_to_verified_number, + send_message_to_verified_number, ) from corehq.apps.sms.models import PhoneNumber from corehq.apps.sms.util import format_message_list @@ -77,7 +77,7 @@ def send_first_message(domain, recipient, phone_entry_or_number, session, respon ) if isinstance(phone_entry_or_number, PhoneNumber): - send_sms_to_verified_number( + send_message_to_verified_number( phone_entry_or_number, message, metadata, @@ -134,7 +134,7 @@ def handle_due_survey_action(domain, contact_id, session_id): messaging_subevent_id=subevent.pk if subevent else None ) resp = FormplayerInterface(session.session_id, domain).current_question() - send_sms_to_verified_number( + send_message_to_verified_number( p, resp.event.text_prompt, metadata,