Update and improve documentation for API.send_direct_message
authorHarmon <Harmon758@gmail.com>
Sat, 10 Apr 2021 22:01:32 +0000 (17:01 -0500)
committerHarmon <Harmon758@gmail.com>
Sat, 10 Apr 2021 22:01:32 +0000 (17:01 -0500)
Automatically use docstring for documentation
Improve method order
Add quick_reply_options and ctas parameters to documentation
Remove quick_reply_type parameter from documentation

docs/api.rst
tweepy/api.py

index f8975bf3f9dc458463262c78967f1b401107b9fe..9cc5739fed6c7f4ba09506a3cb5ba71c8fc38397 100644 (file)
@@ -201,27 +201,7 @@ Sending and receiving events
 
 .. automethod:: API.get_direct_message
 
-
-.. method:: API.send_direct_message(recipient_id, text, [quick_reply_type], \
-                                    [attachment_type], [attachment_media_id])
-
-   Sends a new direct message to the specified user from the authenticating
-   user.
-
-   :param recipient_id: The ID of the user who should receive the direct
-                        message.
-   :param text: The text of your Direct Message. Max length of 10,000
-                characters.
-   :param quick_reply_type: The Quick Reply type to present to the user:
-
-                            * options - Array of Options objects (20 max).
-                            * text_input - Text Input object.
-                            * location - Location object.
-   :param attachment_type: The attachment type. Can be media or location.
-   :param attachment_media_id: A media id to associate with the message.
-                               A Direct Message may only reference a single
-                               media_id.
-   :rtype: :class:`DirectMessage` object
+.. automethod:: API.send_direct_message
 
 
 Account Methods
index 6eafa25d919d1eb75dda639f51cefbdb397b457b..f9af7d51903f4cf7e6c23e47bce39cc7263d7a90 100644 (file)
@@ -2251,6 +2251,57 @@ class API:
             ), id=id, **kwargs
         )
 
+    @payload('direct_message')
+    def send_direct_message(self, recipient_id, text, *, quick_reply_options=None,
+                            attachment_type=None, attachment_media_id=None,
+                            ctas=None, **kwargs):
+        """send_direct_message(recipient_id, text, *, quick_reply_options, \
+                               attachment_type, attachment_media_id, ctas)
+
+        Sends a new direct message to the specified user from the
+        authenticating user.
+
+        :param recipient_id: The ID of the user who should receive the direct
+                             message.
+        :param text: The text of your Direct Message. Max length of 10,000
+                     characters.
+        :param quick_reply_options: Array of Options objects (20 max).
+        :param attachment_type: The attachment type. Can be media or location.
+        :param attachment_media_id: A media id to associate with the message.
+                                    A Direct Message may only reference a
+                                    single media_id.
+        :param ctas: Array of 1-3 call-to-action (CTA) button objects
+
+        :rtype: :class:`DirectMessage` object
+
+        :reference: https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/sending-and-receiving/api-reference/new-event
+        """
+        json_payload = {
+            'event': {'type': 'message_create',
+                      'message_create': {
+                          'target': {'recipient_id': recipient_id},
+                          'message_data': {'text': text}
+                      }
+            }
+        }
+        message_data = json_payload['event']['message_create']['message_data']
+        if quick_reply_options is not None:
+            message_data['quick_reply'] = {
+                'type': 'options',
+                'options': quick_reply_options
+            }
+        if attachment_type is not None and attachment_media_id is not None:
+            message_data['attachment'] = {
+                'type': attachment_type,
+                'media': {'id': attachment_media_id}
+            }
+        if ctas is not None:
+            message_data['ctas'] = ctas
+        return self.request(
+            'POST', 'direct_messages/events/new',
+            json_payload=json_payload, **kwargs
+        )
+
     def media_upload(self, filename, *, file=None, chunked=False,
                      media_category=None, additional_owners=None, **kwargs):
         """ :reference: https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/overview
@@ -2418,38 +2469,6 @@ class API:
             ), command='STATUS', media_id=media_id, upload_api=True, **kwargs
         )
 
-    @payload('direct_message')
-    def send_direct_message(self, recipient_id, text, *, quick_reply_options=None,
-                            attachment_type=None, attachment_media_id=None,
-                            ctas=None, **kwargs):
-        """ :reference: https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/sending-and-receiving/api-reference/new-event
-        """
-        json_payload = {
-            'event': {'type': 'message_create',
-                      'message_create': {
-                          'target': {'recipient_id': recipient_id},
-                          'message_data': {'text': text}
-                      }
-            }
-        }
-        message_data = json_payload['event']['message_create']['message_data']
-        if quick_reply_options is not None:
-            message_data['quick_reply'] = {
-                'type': 'options',
-                'options': quick_reply_options
-            }
-        if attachment_type is not None and attachment_media_id is not None:
-            message_data['attachment'] = {
-                'type': attachment_type,
-                'media': {'id': attachment_media_id}
-            }
-        if ctas is not None:
-            message_data['ctas'] = ctas
-        return self.request(
-            'POST', 'direct_messages/events/new',
-            json_payload=json_payload, **kwargs
-        )
-
     @payload('json')
     def rate_limit_status(self, **kwargs):
         """ :reference: https://developer.twitter.com/en/docs/twitter-api/v1/developer-utilities/rate-limit-status/api-reference/get-application-rate_limit_status