/** * Process attachments for feed. * * @access public * @param array $files * @return array $attachments */ public function process_feed_attachments($files) { /* Prepare attachments array. */ $attachments = array(); /* If Help Scout instance is not initialized, return attachments. */ if (!$this->initialize_api()) { return $attachments; } /* If there are no files, return. */ if (rgblank($files)) { return $attachments; } /* Prepare attachment and add to array */ foreach ($files as $file) { /* Get the file name and location of the file */ $file_name = basename($file); $file_location = str_replace(WP_CONTENT_URL, WP_CONTENT_DIR, $file); /* Get the file's mime type */ $file_info = finfo_open(FILEINFO_MIME_TYPE); $file_mime_type = finfo_file($file_info, $file_location); finfo_close($file_info); /* Prepare the attachment object. */ $attachment = new \HelpScout\model\Attachment(); $attachment->setFileName($file_name); $attachment->setMimeType($file_mime_type); $attachment->setData(file_get_contents($file_location)); /* Create the attachment. */ try { $this->api->createAttachment($attachment); $attachments[] = $attachment; } catch (Exception $e) { $this->log_error(__METHOD__ . "(): Unable to upload attachment; {$e->getMessage()}"); } } return $attachments; }
$conversation->setSubject('I need help!'); $conversation->setMailbox($mailbox); $conversation->setCustomer($customer); $conversation->setType('email'); // A conversation must have at least one thread $thread = new \HelpScout\model\thread\Customer(); $thread->setType('customer'); $thread->setBody('Hello. I need some help.'); $thread->setStatus('active'); // Create by: required $createdBy = new \HelpScout\model\ref\PersonRef(); $createdBy->setId(12345); $createdBy->setType('customer'); $thread->setCreatedBy($createdBy); // Assigned to: not required - defaults to 'anyone' $assignedTo = new \HelpScout\model\ref\PersonRef(); $assignedTo->setId(100); $assignedTo->setType('user'); $thread->setAssignedTo($assignedTo); // Cc and Bcc $thread->setCcList(array('*****@*****.**', '*****@*****.**')); $thread->setBccList(array('*****@*****.**', '*****@*****.**')); // Attachments: attachments must be sent to the API before they can // be used when creating a thread. Use the hash value returned when // creating the attachment to associate it with a ticket. $attachment = new \HelpScout\model\Attachment(); $attachment->setHash('j894hg93gh9egh934gh34g8hjhvbdjvhbweg3'); $thread->setAttachments(array($attachment)); $conversation->setThreads(array($thread)); $conversation->setCreatedBy($createdBy); $client->createConversation($conversation);
use HelpScout\ApiClient; $client = ApiClient::getInstance(); $client->setKey(HS_API_KEY); // The mailbox associated with the conversation $mailbox = new \HelpScout\model\ref\MailboxRef(); $mailbox->setId(49350); $failed = array(); foreach ($backlog as $key => $row) { try { // Attachments: attachments must be sent to the API before they can // be used when creating a thread. Use the hash value returned when // creating the attachment to associate it with a ticket. $attachments = array(); if (!empty($row['attachment'])) { foreach (explode(' , ', $row['attachment']) as $url) { $attachment = new HelpScout\model\Attachment(); if (endswith($url, '.png')) { $attachment->setMimeType('image/png'); } if (endswith($url, '.jpg') || endswith($url, '.jpeg')) { $attachment->setMimeType('image/jpeg'); } $attachment->setFileName(filename_from_url($url)); $attachment->setData(file_get_contents($url)); $client->createAttachment($attachment); $attachments[] = $attachment; } } // Create the customer $customer = new \HelpScout\model\ref\CustomerRef(); $customer->setId(null);