helpscout / helpscout-api-php

PHP Wrapper for the Help Scout API
MIT License
99 stars 62 forks source link

Conversation appears as created by account owner #163

Closed jproy418 closed 5 years ago

jproy418 commented 5 years ago

Hi,

Is it possible to decide the conversation owner? Right now they all appear as created by the account owner or the customer. We would like to put the support agent who received the call as the owner of the conversation.

I've try a lot of combinations with threads, conversation type and the method setCreatedByUser(). The method setCreatedByUser() seem to have no effect. When the conversation is created with a PhoneTread(), it's the picture (and the name) of the account owner that appears in the mailbox. When the conversation is created with a CustomerThread(), it's the name of the customer that appears.

That's what my code look like:

// Set customer
$customer = new Customer();
$customer->setId($id_customer);
$user = $this->get_user($user_id);

if($canal == 'comptoir') {
      $subject = 'Visite au comptoir le ' . date( 'Y/m/j H:i' ) . " : $objet";
      $type = 'email'; // email, chat, phone
      $thread = new CustomerThread();
      $thread->setCustomer($customer);
      $thread->setText('Objet de la visite: <br/>' . $content . '-');
      $thread->setCreatedByUser($user);
} elseif($canal == 'appel-entrant') {
      $subject = "Appel entrant $tel: $objet";
      $type = 'phone';
      $thread = new PhoneThread();
      $thread->setCustomer($customer);
      $thread->setText('Objet de l\'appel: <br/>' . $content . '-');
      $thread->setCreatedByUser($user);
} else {
      $subject = 'Appel sortant le ' . date( 'Y/m/j H:i' );
      $type = 'phone';
      $thread = new PhoneThread();
      $thread->setCustomer($customer);
      $thread->setText('Objet de l\'appel: <br/>' . $content . '-');
      $thread->setCreatedByUser($user);
}

// set conversation
$conversation = new Conversation();
$conversation->setSubject($subject);
$conversation->setStatus('closed'); // closed, open
$conversation->setType($type);
$conversation->setAssignTo($user_id);
$conversation->setMailboxId($this->id_mailbox);
$conversation->setCustomer($customer);
$conversation->setThreads(new Collection([$thread,]));
$conversation->setCreatedByUser($this->get_user($user_id));
$id_conversation = $this->client->conversations()->create($conversation);
bkuhl commented 5 years ago

Hey! The good news is your code is correct. The bad news is this seems to have been a bug in the SDK. I've included a fix in this PR: https://github.com/helpscout/helpscout-api-php/pull/167

jproy418 commented 5 years ago

It's working! Thank you!