[tutorial] ERPNext Notification to Flock App - Webhook


ErpNext ->Setup -> Flockhook

Flock notification for ErpNext
#How to Install

Install App

  1. bench get-app flock https://prashanta@bitbucket.org/prashanta/flock.git

  2. bench install-app flock

#In Flock Menu

  1. Go to https://docs.flock.com/display/flockos/Create+An+Incoming+Webhook

  2. Create a “Incoming WebHooks”

  3. Copy the generated Webhook URL value

#In Frappe/ERPNext Menu

  1. Go to Setup -> Flockhook

  2. Set the the values.

Mandatory Fields:

* Request URL = Flock generated Incoming webhook URL

* Doctype = ErpNext Doctype name

* Event = Select an event (i.e after_insert,on_submit,on_cancel,on_trash)

Example Message Body

You can setup message body like Email Alert message section use doctype fields name like-

{% for i in doc.items %}
Item: {{i.item_name }} Qty: {{ i.qty }}
{% endfor %}

<br>Customer: {{ doc.customer }}
<br>Amount: {{ doc.total_amount }}
<br>Amount: {{ doc.company }}
9 Likes

use https://pypi.python.org/pypi/six for urlparse
use requests instead of httplib

Ideally, use (or extend with PR) Webhooks in frappe. It involves, caching, background jobs, three retries and logs errors.

https://bitbucket.org/prashanta/flock/src/73dc36b9d03f1a30051a6b0c557e43215663cc91/flock/events.py?at=master&fileviewer=file-view-default#events.py-27

Frappe’s Webhook makes a POST request :white_check_mark:
You can add additional headers in Frappe’s Webhook :white_check_mark:
You can set custom key for value in frappe doctype. e.g. “modified_by” field can be set to “user”, “text” can be any other field on doctype. :white_check_mark:

Only thing missing is data like this for key “attachments” :

Simple workaround without any development would be add “custom” child table or a code field on doctype which sets this data.

{   ...
    "attachments": [{
        "title": doc.name,
        "color": color,
        "views": {
            "flockml": "<flockml>"+message+"</flockml>",
        }
    }]
}

Or if you are going for development, extend Webhook such that it can be used with the power of jinja2 on any doctype to attach a custom dict to the webhook data.

5 Likes

@revant_one trying to have this running but when added webhook events After_insert and on_submit the system give me this type of message and the doc is not Submitted nor saved!!

image

If using the frappe webhooks
Here is my setup

After submitting or saving on the Error log this is shown

What is missing to make it work in both Webhooks and if using Frappe webhooks can this be

Kindly git pull again then try. issue fixed.

Thanks. For which one? Frappe or Flock because I have just updated and tested… It works but the message on the phone received like this

Uploading…

How to format the information?

Make a Git Pull to flock from ~/frappe-bench/apps/flock.

@Prashanta_Mahato i have done… and is working just the information format!!!

From my previous reply here is the image when i receive the info on the phone

Fine. put {{doc.grand_total}} OR {{doc.rounded_total}} in message body instead of total_amount.

Sorry my fault did not check the right name fields for this Doctype … solved.
Now if want to receive messages from Flock !!! i need to create the event to receive as API ?

Using requests I am getting the error: SSLError: (“bad handshake: Error([(‘SSL routines’, ‘ssl3_get_server_certificate’, ‘certificate verify failed’)],)”,) request python

I have to installed requests[security] ???

I have to add the custom field in all doctype (Use for webhook)???