freescout
freescout copied to clipboard
Show content from first email in auto reply
Hello,
is it possible to include the first email (that the customer sends to a mailbox) in the automatic reply?
It is always important to me that I see my request in the automatic e-mail reply I receive from support, so that I know what I have written to support.
Best regards maisen20
I don't know if this is a clean and good solution, but it seems to work for me.
I changed the function replaceMailVars() in file "app/Misc/Mail.php":
/**
* Replace mail vars in the text.
*/
public static function replaceMailVars($text, $data = [], $escape = false)
{
// Available variables to insert into email in UI.
$vars = [];
/* OLD
if (!empty($data['conversation'])) {
$vars['{%subject%}'] = $data['conversation']->subject;
$vars['{%conversation.number%}'] = $data['conversation']->number;
$vars['{%customer.email%}'] = $data['conversation']->customer_email;
}
*/
if (!empty($data['conversation'])) {
$vars['{%subject%}'] = $data['conversation']->subject;
$vars['{%conversation.number%}'] = $data['conversation']->number;
$vars['{%customer.email%}'] = $data['conversation']->customer_email;
$data['conversation']->load(['threads' => function ($query) {
$query->latest('created_at')->first();
}]);
$vars['{%conversation.body%}'] = ($data['conversation']->threads()->first()) ? $data['conversation']->threads()->first()->body : '';
}
if (!empty($data['mailbox'])) {
$vars['{%mailbox.email%}'] = $data['mailbox']->email;
$vars['{%mailbox.name%}'] = $data['mailbox']->name;
$vars['{%mailbox.fromName%}'] = $data['mailbox']->getMailFrom(!empty($data['user']) ? $data['user'] : null)['name'];
}
if (!empty($data['customer'])) {
$vars['{%customer.fullName%}'] = $data['customer']->getFullName(true);
$vars['{%customer.firstName%}'] = $data['customer']->getFirstName(true);
$vars['{%customer.lastName%}'] = $data['customer']->last_name;
$vars['{%customer.company%}'] = $data['customer']->company;
}
if (!empty($data['user'])) {
$vars['{%user.fullName%}'] = $data['user']->getFullName();
$vars['{%user.firstName%}'] = $data['user']->getFirstName();
$vars['{%user.phone%}'] = $data['user']->phone;
$vars['{%user.email%}'] = $data['user']->email;
$vars['{%user.jobTitle%}'] = $data['user']->job_title;
$vars['{%user.lastName%}'] = $data['user']->last_name;
$vars['{%user.photoUrl%}'] = $data['user']->getPhotoUrl();
}
$vars = \Eventy::filter('mail_vars.replace', $vars, $data);
if ($escape) {
foreach ($vars as $i => $var) {
$vars[$i] = htmlspecialchars($var ?? '');
}
}
return strtr($text, $vars);
}
And in the auto reply message i use the variable {%conversation.body%}
This works great but it breaks the "New Conversation" option. Any way to fix this / prevent this?
We bought a license and would also like a patch to get this functionality.
@bekre10 what do you mean by:
This works great but it breaks the "New Conversation" option.
?
This works great but it breaks the "New Conversation" option. Any way to fix this / prevent this?
I also don't understand what you mean. Everything works for me so far.

See screenshot. I can't create a new ticket anymore as long as the script is in app/Misc/Mail.php Once I remove it, I can create a new ticket again.
The script itself is working fine for what it's intended. Just a side effect apparently.
See screenshot. I can't create a new ticket anymore as long as the script is in app/Misc/Mail.php Once I remove it, I can create a new ticket again.
The script itself is working fine for what it's intended. Just a side effect apparently.
Okay now after i updated freescout to newest version i saw the problem.
You need to replace following line...
$vars['{%conversation.body%}'] = $data['conversation']->threads()->first()->body;
...with:
$vars['{%conversation.body%}'] = ($data['conversation']->threads()->first()) ? $data['conversation']->threads()->first()->body : '';
I've changed this in my comment above too. https://github.com/freescout-helpdesk/freescout/issues/2006#issuecomment-1131785761
Is it possible that someone implements this feature here at Github/Freescout so that it is also possible to append the first message in the auto-reply in future releases of freescout?
Unfortunately I do not know how to add or initiate this customization here.
@maisen20 Awesome, thank you so much.
You're welcome.
I have now programmed the whole function as a module. Thus, this function should work for me even after an update of Freescout. But I have to test that when there is a update for freescout.
@maisen20 That's great. Was cumbersome so far to insert the code again after each update. Great work :)
I've programmed the module only for myself and I have not published or made it available anywhere. I've made this very simple and rudimentary.
If I knew more exactly how to make such a module available, I would do it. 🫣
So, I have now made my module available. Maybe you @bekre10 can install and use it, if it works. freescout-extended-mail-vars
@maisen20 Thank you so much. I will try tomorrow or the day after and let you know. If it works, I will buy you a coffee. Great community here. Love it.
@bekre10 You're welcome. You can write me if there are problems or you could test it and set it up.
If you have ideas for more modules, let me know.
Notice: After updating freescout from version 1.8.35 to 1.8.36, my module seems to work without problems.
Hello @maisen20 It works without issue, thanks for the great help. I already bought you a coffee yesterday :)
Hi @bekre10 ,
thank you very much for the coffee, it's my first one =). I'm glad it's working fine.
@maisen20 Not sure you are interested, but I need a module for reports. I do have the official "Reports" module but it doesn't show me the number of tickets created during a month by a certain company (identified by their domain). This is helpful for billing. I have also tried via search function but it only can search based on users who submitted the ticket but not the entire domain.
Hi @bekre10
I assume that this module is a little bit more comprehensive. Currently I have a lot to do but maybe I have time in the next weeks/months, then I can have a look at it.
@maisen20 I am ok to pay for it if you call a fair price. Maybe you can get it into their official module list so you can make a bit more money out of it. Not sure they allow this though.
Hi @bekre10
I don't use and don't know the report module, but could you maybe solve this by assigning a tag from the company to each ticket?
Hello @maisen20, I don't see any option for tags in the reports module. That's not supported there.
When I look at the first screenshot @ https://freescout.net/module/reports/, it says that you can also evaluate tags with the Tags module. Or do I understand this wrong? So you could add the unique tag of the "customer" to every ticket, or so I thought.
It was just an idea, I don't know the report module.
@maisen20 now that you mentioned it I have looked at the report module description and indeed, it is mentioned there. I will try it with tags. Thanks a lot for the hint.
@maisen20 that works perfectly. Either I was bling from the beginning or they just added the tags option for reports recently. Appreciate you pointed me in the right direction :)
@bekre10 glad I could help ;)