helpscout / helpscout-api-php

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

Passing HTML to getText method of ReplyThread results in space characters at ends of lines #202

Closed nwhetsell closed 4 years ago

nwhetsell commented 5 years ago

Consider this (somewhat pseudo-) code:

<?php
require_once 'vendor/autoload.php';

use HelpScout\Api\ApiClientFactory;
use HelpScout\Api\Conversations\Conversation;
use HelpScout\Api\Conversations\Threads\ReplyThread;
use HelpScout\Api\Entity\Collection;

$HelpScoutClient = ApiClientFactory::createClient();
$HelpScoutClient->useClientCredentials(⟨app ID⟩, ⟨app secret⟩);

$customer = $HelpScoutClient->customers()->get(⟨customer ID⟩);

$thread = new ReplyThread();
$thread->asDraft();
$thread->setCustomer($customer);
$thread->setText(
  'paragraph 1<br><br>' .
  'paragraph 2<br>'
);

$conversation = new Conversation();
$conversation->setCustomer($customer);
$conversation->setMailboxId(⟨mailbox ID⟩);
$conversation->setPending();
$conversation->setSubject('Subject');
$conversation->setThreads(new Collection([$thread]));
$conversation->setType('email');
$conversationID = $HelpScoutClient->conversations()->create($conversation);

echo "Conversation ID is $conversationID" . PHP_EOL;
?>

On Help Scout, the email unexpectedly has space characters after both paragraphs; the email on Help Scout is

paragraph␣1␣

paragraph␣2␣

rather than

paragraph␣1

paragraph␣2

where I’m using to denote a space character.

This is also the case if $thread->asDraft() is ommitted; the sent email has space characters after both paragraphs.

bkuhl commented 5 years ago

This is probably a side effect of the sanitization/parsing that takes place within the Help Scout application. Is this causing an issue on your end?

nwhetsell commented 5 years ago

Having extra spaces at the ends of paragraphs isn’t the end of the world, but yes, pretty much. As it stands now, it doesn’t seem like the Help Scout API can send emails that are exactly what you’d get if you used the built-in editor on helpscout.net, since there are extra spaces at the ends of paragraphs.