// 1. First need to decide who I'm sending it to. // All I have is an email address. This may or may not be an existing customer. // Either way, Help Scout will create the customer if the customer does not yet exist. $customerRef = $client->getCustomerRefProxy(null, '*****@*****.**'); // 2. Decide which mailbox this conversation will be created in $mailboxRef = $client->getMailboxProxy(2431); // 3. Now let's start constructing the conversation $conversation = new \HelpScout\model\Conversation(); $conversation->setSubject('Thanks for contacting us'); $conversation->setMailbox($mailboxRef); $conversation->setCustomer($customerRef); // 4. Let's set the conversation type to "email" (as opposed to a chat or phone call) $conversation->setType('email'); // 5. Every conversation MUST HAVE at least one thread. // To send an email to the customer, the thread type must be a "Message" thread $thread = new \HelpScout\model\thread\Message(); $thread->setBody('Hey there - sorry to hear you\'ve had trouble using our product. We\'ve contacted an engineer and he will be touching base shortly'); // 6. Now, we have to say "who" created the message. Message threads can only be created by // registered users of Help Scout. So it must be from soneone on your team. // 6.1 You could use the person associated with the current API key: // $userRef = $client->getUserMe()->toRef(); // 6.2 You could use a specific user $userRef = $client->getUserRefProxy(1234); $thread->setCreatedBy($userRef); // Need to cc or bcc anyone? //$thread->setCcList(array("*****@*****.**", "*****@*****.**")); //$thread->setBccList(array("*****@*****.**", "*****@*****.**")); //7. Add the thread to the conversation $conversation->addLineItem($thread); // 8. Set the conversation "createdBy" (usually same person that creates the message thread) $conversation->setCreatedBy($userRef);
<?php include_once 'ApiClient.php'; use HelpScout\ApiClient; $client = ApiClient::getInstance(); $client->setKey('example-key'); // valid convo id that already exists $conversationId = 1522392; // Message threads are ones created by users of Help Scout and will be emailed out to customers $thread = new \HelpScout\model\thread\Message(); $thread->setBody('Hey there - sorry you\'re having issues. We\'ve contacted an engineer and he will get back with you shortly. Stay tuned.'); // Created by: required // The ID given must be a registered user of Help Scout $thread->setCreatedBy($client->getUserRefProxy(4)); $client->createThread($conversationId, $thread); echo $thread->getId();
/** * Add note to Help Scout conversation. * * @access public * @param int $note_id - The ID of the created note. * @param int $entry_id - The ID of the entry the note belongs to. * @param int $user_id - The ID of the user who created the note. * @param string $user_name - The name of the user who created the note. * @param string $note - The note contents. * @param string $note_type - The note type. * @return void */ public function add_note_to_conversation($note_id, $entry_id, $user_id, $user_name, $note, $note_type) { /* If Add Note checkbox not selected, exit. */ if (rgpost('helpscout_add_note') != '1') { return; } /* Get the entry. */ $entry = GFAPI::get_entry($entry_id); $conversation_id = $this->get_entry_converstaion_id($entry); /* If API is not initialized or entry does not have a Help Scout conversation ID, exit. */ if (!$this->initialize_api() || !$conversation_id) { return; } /* Get API user. */ $api_user = $this->api->getUserMe(); /* Create note object. */ $hs_note = new \HelpScout\model\thread\Message(); $hs_note->setCreatedBy($this->api->getUserRefProxy($api_user->getId())); $hs_note->setBody($note); $hs_note->setType('note'); try { /* Post note to conversation. */ $this->api->createThread($conversation_id, $hs_note); /* Log that note was added. */ $this->log_debug(__METHOD__ . '(): Note was successfully added to conversation.'); } catch (Exception $e) { /* Log that note was not added. */ $this->log_error(__METHOD__ . '(): Note was not added to conversation; ' . $e->getMessage()); } }