freescout icon indicating copy to clipboard operation
freescout copied to clipboard

Show content from first email in auto reply

Open Nexulo opened this issue 3 years ago • 2 comments

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

Nexulo avatar May 19 '22 07:05 Nexulo

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%}

Nexulo avatar May 19 '22 14:05 Nexulo

This works great but it breaks the "New Conversation" option. Any way to fix this / prevent this?

bekre10 avatar Sep 03 '22 16:09 bekre10

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.

?

patforg avatar Oct 03 '22 22:10 patforg

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.

Nexulo avatar Nov 18 '22 06:11 Nexulo

freescount-sc1

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.

bekre10 avatar Nov 18 '22 07:11 bekre10

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

Nexulo avatar Nov 18 '22 10:11 Nexulo

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.

Nexulo avatar Nov 18 '22 10:11 Nexulo

@maisen20 Awesome, thank you so much.

bekre10 avatar Nov 18 '22 17:11 bekre10

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.

Nexulo avatar Nov 21 '22 08:11 Nexulo

@maisen20 That's great. Was cumbersome so far to insert the code again after each update. Great work :)

bekre10 avatar Nov 21 '22 14:11 bekre10

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. 🫣

Nexulo avatar Nov 21 '22 15:11 Nexulo

So, I have now made my module available. Maybe you @bekre10 can install and use it, if it works. freescout-extended-mail-vars

Nexulo avatar Nov 22 '22 14:11 Nexulo

@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 avatar Nov 22 '22 15:11 bekre10

@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.

Nexulo avatar Nov 24 '22 10:11 Nexulo

Notice: After updating freescout from version 1.8.35 to 1.8.36, my module seems to work without problems.

Nexulo avatar Nov 28 '22 09:11 Nexulo

Hello @maisen20 It works without issue, thanks for the great help. I already bought you a coffee yesterday :)

bekre10 avatar Nov 30 '22 01:11 bekre10

Hi @bekre10 ,

thank you very much for the coffee, it's my first one =). I'm glad it's working fine.

Nexulo avatar Nov 30 '22 05:11 Nexulo

@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.

bekre10 avatar Dec 01 '22 03:12 bekre10

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.

Nexulo avatar Dec 01 '22 06:12 Nexulo

@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.

bekre10 avatar Dec 01 '22 07:12 bekre10

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?

Nexulo avatar Dec 08 '22 13:12 Nexulo

Hello @maisen20, I don't see any option for tags in the reports module. That's not supported there.

bekre10 avatar Dec 13 '22 15:12 bekre10

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.

Nexulo avatar Dec 13 '22 15:12 Nexulo

@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.

bekre10 avatar Dec 13 '22 16:12 bekre10

@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 avatar Dec 13 '22 16:12 bekre10

@bekre10 glad I could help ;)

Nexulo avatar Dec 14 '22 05:12 Nexulo