Closed csuard closed 1 year ago
Hey @CorentinSUTT!
A Conversation
itself doesn't contain any text, but it contains a list of Thread
s, which represent the different items within the conversation timeline (customer replies, notes, etc). The first thread in the list represents the last reply, and the last thread represents the email that initiated the conversation.
If you already fetched a Conversation
object, it provides a getThreads()
method that returns all the threads that were eagerly loaded when fetching the conversation.
Alternatively, you can directly fetch the paginated threads providing a conversation ID, as you can see in examples/threads.php.
Once you have the Thread
objects, you can call getText()
to get the content.
Hope this helps!
Thanks a lot for your answer! And how do I get only the latest thread of the conversation?
@CorentinSUTT
Threads are by default sorted by createdAt
(from newest to oldest), which means if you want to get the most recent thread, you can just fetch the Conversation
and get the first item from the list of threads:
$request = (new ConversationRequest())->withThreads();
$conversation = $client->conversations()->get($conversationId, $request);
$mostRecent = $conversation->getThreads()[0]
If you want to get the oldest thread (the initial email that started the conversation), and you want your solution to work for any number of threads, then you will need to fetch the Thread
s directly, and then get the last one:
$threads = $client->threads()->list($conversationId)->getLastPage();
$oldestThread = end($threads);
Hi,
Thanks a lot for all your help.
I still have a little issue.
I made the following code:
$request = (new ConversationRequest())->withThreads();
$conversation = $client->conversations()->get($id, $request);
$mostRecent = $conversation->getThreads()[0];
$content = $mostRecent->getText();
Sometimes, it works. Sometimes, it gives me NULL as content. Do you know where it can come from?
I would like to know how to get the content of a conversation. Is it possible? Actually, I am able to get the preview and the subject of the mail but I can't find how to get the content of the mail. Do you know a way to get it?
Thanks a lot!