1 <?php
2
3 namespace MailChimp\Conversations;
4
5 use MailChimp\MailChimp as MailChimp;
6
7 class Conversations extends MailChimp
8 {
9
10 /**
11 * Get a list of conversations for the account.
12 *
13 * Available query fields:
14 * array["fields"] array list of strings of response fields to return
15 * array["exclude_fields"] array list of strings of response fields to exclude (not to be used with "fields")
16 * array["count"] int number of records to return
17 * array["offset"] int number of records from a collection to skip.
18 * array["has_unread_messages"] string Whether the conversation has any unread messages.
19 * array["list_id"] string The unique id for the list.
20 * array["campaign_id"] string The unique id for the camapign.
21 *
22 * @param array $query (See Above) OPTIONAL associative array of query parameters.
23 * @return object
24 */
25 public function getConversations(array $query = [])
26 {
27 return self::execute("GET", "conversations", $query);
28 }
29
30 /**
31 * Get details about an individual conversation.
32 *
33 * Available query fields:
34 * array["fields"] array list of strings of response fields to return
35 * array["exclude_fields"] array list of strings of response fields to exclude (not to be used with "fields")
36 *
37 * @param string $conversation_id
38 * @param array $query (See Above) OPTIONAL associative array of query parameters.
39 * @return object
40 */
41 public function getConversation($conversation_id, array $query = [])
42 {
43 return self::execute("GET", "conversations/{$conversation_id}", $query);
44 }
45
46 /**
47 * Get messages from a specific conversation.
48 *
49 * Available query fields:
50 * array["fields"] array list of strings of response fields to return
51 * array["exclude_fields"] array list of strings of response fields to exclude (not to be used with "fields")
52 * array["is_read"] string Whether a conversation message has been marked as read.
53 * array["before_timestamp"] string Restrict the response to messages created before the set time.
54 * ISO 8601 time format: 2015-10-21T15:41:36+00:00.
55 * array["since_timestamp"] string Restrict the response to messages created after the set time.
56 * ISO 8601 time format: 2015-10-21T15:41:36+00:00.
57 *
58 * @param string $conversation_id
59 * @param array $query (See Above) OPTIONAL associative array of query parameters.
60 * @return object
61 */
62 public function getConversationMessages($conversation_id, array $query = [])
63 {
64 return self::execute("GET", "conversations/{$conversation_id}/messages", $query);
65 }
66
67 /**
68 * Get an individual message in a conversation.
69 *
70 * Available query fields:
71 * array["fields"] array list of strings of response fields to return
72 * array["exclude_fields"] array list of strings of response fields to exclude (not to be used with "fields")
73 *
74 * @param string $conversation_id
75 * @param string $message_id
76 * @param array $query (See Above) OPTIONAL associative array of query parameters.
77 * @return object
78 */
79 public function getConversationMessage($conversation_id, $message_id, array $query = [])
80 {
81 return self::execute("GET", "conversations/{$conversation_id}/messages/{$message_id}", $query);
82 }
83
84 /**
85 * Post a new message to a conversation
86 *
87 * @param string $conversation_id
88 * @param string $from_email
89 * @param boolean $read
90 * @param array $optional_settings
91 * @return object
92 */
93 public function postMessage($conversation_id, $from_email, $read = false, array $optional_settings = null)
94 {
95 $optional_fields = ["subject", "message"];
96 $data = [
97 "from_email" => $from_email,
98 "read" => $read
99 ];
100
101 // If the optional fields are passed, process them against the list of optional fields.
102 if (isset($optional_settings)) {
103 $data = array_merge($data, self::optionalFields($optional_fields, $optional_settings));
104 }
105
106 return self::execute("POST", "conversations/{$conversation_id}/messages", $data);
107 }
108
109 }
110