shridarpatil / frappe_whatsapp

WhatsApp cloud integration for frappe
https://www.youtube.com/watch?v=nq5Kcc5e1oc
Other
188 stars 169 forks source link

Not able to send Message with Attachment (pdf) #77

Closed elbeicktalat closed 4 months ago

elbeicktalat commented 4 months ago

Hi, Thanks for the awesome plugin,

I have exact 2 Whatsapp templates, one plain text the other comes with document, the issue is that when i use the first one plain text (no media) it's working perfectly, but if i use the one with document, no message begins sent, i think it's related to the pdf file download.

I have already test the print via /api/method/frappe.utils.print_format.download_pdf there is no issue.

WhatsApp Message

  1. Plain text

    image
  2. With (pdf) Attachment

    image

Please try to fix this or inform me if there is any hidden step to do.

Ah just to be sure, my app on meta still in dev mode, can be this the issue? Note that I'm able to send text messages, but only with pdf not working.

shridarpatil commented 4 months ago

There could be multiple reasons for pdf not being sent

  1. Check whether your template is approved or not
  2. Meta should be able to access this endpoint /api/method/frappe.utils.print_format.download_pdf make sure its available as public.
  3. As you said your still on dev mode make sure that the number for which your trying to send message is registered on meta

It doesn't matter if your still on dev mode, you should still get the message.

You can check whatspp notification logs for more details.

elbeicktalat commented 4 months ago

@shridarpatil Thanks for the answer,

  1. Check whether your template is approved or not

Yes, it's approved .

  1. Meta should be able to access this endpoint /api/method/frappe.utils.print_format.download_pdf make sure its available as public.

How can I make this endpoint as public? Because as you said I tried to print without login it didn't work so probably this is the problem. I have to do something on meta side or only on ERPNext side? Please explain in detail.

  1. As you said your still on dev mode make sure that the number for which your trying to send message is registered on meta

If I'm in prod mode I still have to register the receiver number? Probably not?

elbeicktalat commented 4 months ago

Confirmed, it's permission issue.

Now the question is how to allow the print without authentication? I saw that the frappe.utils.print_format.download_pdf method is allow_guest I think this means it's public see here

Traceback (most recent call last):
  File "apps/frappe/frappe/utils/pdf.py", line 87, in get_pdf
    filedata = pdfkit.from_string(html, options=options or {}, verbose=True)
  File "env/lib/python3.10/site-packages/pdfkit/api.py", line 75, in from_string
    return r.to_pdf(output_path)
  File "env/lib/python3.10/site-packages/pdfkit/pdfkit.py", line 201, in to_pdf
    self.handle_error(exit_code, stderr)
  File "env/lib/python3.10/site-packages/pdfkit/pdfkit.py", line 155, in handle_error
    raise IOError('wkhtmltopdf reported an error:\n' + stderr)
OSError: wkhtmltopdf reported an error:
Exit with code 1 due to network error: ContentOperationNotPermittedError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 110, in application
    response = frappe.api.handle(request)
  File "apps/frappe/frappe/api/__init__.py", line 49, in handle
    data = endpoint(**arguments)
  File "apps/frappe/frappe/api/v1.py", line 36, in handle_rpc_call
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 49, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/handler.py", line 85, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "apps/frappe/frappe/__init__.py", line 1684, in call
    return fn(*args, **newargs)
  File "apps/frappe/frappe/utils/typing_validations.py", line 31, in wrapper
    return func(*args, **kwargs)
  File "apps/frappe/frappe/utils/print_format.py", line 134, in download_pdf
    pdf_file = frappe.get_print(
  File "apps/frappe/frappe/__init__.py", line 2093, in get_print
    return get_pdf(html, options=pdf_options, output=output) if as_pdf else html
  File "apps/frappe/frappe/utils/pdf.py", line 95, in get_pdf
    frappe.throw(_("PDF generation failed because of broken image links"))
  File "apps/frappe/frappe/__init__.py", line 578, in throw
    msgprint(
  File "apps/frappe/frappe/__init__.py", line 550, in msgprint
    _raise_exception()
  File "apps/frappe/frappe/__init__.py", line 501, in _raise_exception
    raise exc
frappe.exceptions.ValidationError: PDF generation failed due to broken image links
shridarpatil commented 4 months ago

Looking at the above error I can see that pdf generation is failing due to some image link can you check that and fix? After that it should work fine.

elbeicktalat commented 4 months ago

Oh, it does make sense since some image is private.

My bad 😅Now it's working