From 28bc45b825b7176c3486b988e39268ccdc981507 Mon Sep 17 00:00:00 2001 From: Narayana Shanbhogh Date: Fri, 22 May 2026 19:22:46 +0530 Subject: [PATCH] Add messages.create for POST /v1/Account/{auth_id}/Message/ Auto-generated by Rune from plivo/api-messaging#624. --- CHANGELOG.md | 6 ++++++ examples/messages_create.py | 14 ++++++++++++++ plivo/resources/messages.py | 8 +++++--- setup.py | 2 +- tests/resources/test_messages.py | 18 +++++++++++++++++- 5 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 examples/messages_create.py diff --git a/CHANGELOG.md b/CHANGELOG.md index b3bc619d..6e83f59d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ # Change Log +## [4.60.2](https://github.com/plivo/plivo-python/tree/v4.60.2) (2026-05-22) +**Feature - Messages API parameter update** +- Added `allow_dtmf` optional parameter to messages.create (POST /v1/Account/{auth_id}/Message/) + +_Source: plivo/api-messaging#624_ + ## [4.60.1](https://github.com/plivo/plivo-python/tree/v4.60.1) (2026-04-17) **Bug Fix - PhoneNumber Compliance API** - Fixed Requirements.get() sending None values as query params when not provided diff --git a/examples/messages_create.py b/examples/messages_create.py new file mode 100644 index 00000000..2847490f --- /dev/null +++ b/examples/messages_create.py @@ -0,0 +1,14 @@ +# Example of sending a message with allow_dtmf using Plivo API + +import plivo + +client = plivo.RestClient("auth_id", "auth_token") + +response = client.messages.create( + src='14151234567', # Sender's phone number with country code + dst='14157654321', # Receiver's phone number with country code + text='Test message with DTMF allowed', + allow_dtmf=True +) + +print(response) \ No newline at end of file diff --git a/plivo/resources/messages.py b/plivo/resources/messages.py index 78692369..adc79e32 100644 --- a/plivo/resources/messages.py +++ b/plivo/resources/messages.py @@ -46,7 +46,8 @@ class Messages(PlivoResourceInterface): location=[optional(is_location())], dlt_entity_id=[optional(of_type(six.text_type))], dlt_template_id=[optional(of_type(six.text_type))], - dlt_template_category=[optional(of_type(six.text_type))] + dlt_template_category=[optional(of_type(six.text_type))], + allow_dtmf=[optional(of_type_exact(bool))] ) def create(self, dst, @@ -66,7 +67,8 @@ def create(self, location=None, dlt_entity_id=None, dlt_template_id=None, - dlt_template_category=None): + dlt_template_category=None, + allow_dtmf=None): if src in dst.split('<'): raise ValidationError( 'destination number cannot be same as source number') @@ -161,4 +163,4 @@ def list(self, 'GET', ('Message', ), to_param_dict(self.list, locals()), response_type=ListMessagesResponseObject, - objects_type=Message) + objects_type=Message) \ No newline at end of file diff --git a/setup.py b/setup.py index 5aa4ad1e..eb9e19ef 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup( name='plivo', - version='4.60.1', + version='4.60.2', description='A Python SDK to make voice calls & send SMS using Plivo and to generate Plivo XML', long_description=long_description, url='https://github.com/plivo/plivo-python', diff --git a/tests/resources/test_messages.py b/tests/resources/test_messages.py index e872db06..c723ee8d 100644 --- a/tests/resources/test_messages.py +++ b/tests/resources/test_messages.py @@ -59,6 +59,22 @@ def test_send_message_with_no_src_powerpack(self): dst='1234', text='Abcd') + @with_response(202) + def test_send_message_with_allow_dtmf(self): + expected_response = {'message_uuid': 'newmessageuuid'} + self.client.set_expected_response( + status_code=202, data_to_return=expected_response) + + test_message = self.client.messages.create( + src='1234', dst='12345', text='Test message', allow_dtmf=True) + + self.assertResponseMatches(test_message) + self.assertUrlEqual(self.client.current_request.url, + self.get_url('Message')) + self.assertEqual(self.client.current_request.method, 'POST') + self.assertEqual(test_message.message_uuid, + expected_response['message_uuid']) + @with_response(200) def test_get(self): message_uuid = 'message_uuid' @@ -91,4 +107,4 @@ def test_list(self): self.assertEqual(len(list(messages)), 20) self.assertUrlEqual(self.client.current_request.url, self.get_url('Message')) - self.assertEqual(self.client.current_request.method, 'GET') + self.assertEqual(self.client.current_request.method, 'GET') \ No newline at end of file