Skip to main content

Cloud Bitrix24 and Post Tracking - SOAP Integration via AWS Lambda

I like to use Serverless AWS technology: Lambda and API Gateway to customize the cloud Bitrix24.
It is comfortable, simple, elegant and very cheap.

For example, AWS Lambda gives us the possibility to check post tracking numbers for free for the first year through the Post SOAP service. After a year, if my measurements and calculations are correct, checking 100,000 post tracking numbers will cost about $12.

 What do we need for this:
1) Get the login and the password for integration on the Russian Post website: https://www.pochta.ru/support/business/api

2) Prepare a Lambda Layer with a library for working with SOAP. I chose the open-source Zeep library. How to pack Python3 Zeep library in a Lambda Layer, I wrote earlier on my blog: http://bedrosovayulia.blogspot.com/2019/07/how-to-reate-aws-lambda-layer-with-zeep.html

3) On the side of Bitrix24, we need to create an inbound webhook with the right to send messages and with access to the universal lists (in my case) or, perhaps, to CRM - depending on where you need to save the checking result.

 4) Write a business process in Bitrix24, which will call the outbound webhook, giving it the post tracking number, as well as the ID of the element and information block, in which the result of the check must be saved.

 5) Write an AWS Lambda function that gets data from Bitrix24, requests the status of the tracking number from Post SOAP service and return the result to Bitrix24 via the inbound webhook.

 6) Configure the API Gateway for our Lambda function. I described this process in detail earlier: http://bedrosovayulia.blogspot.com/2019/07/aws-lambda-and-api-gateway-for-bitrix24.html

I want to talk about the integration scenarios of post tracking that I implemented in the cloudy Bitrix24 for my company.

Usually, I scan all incoming and outgoing correspondence and put them on a list that I created specifically for this in Bitrix24 - Сorrespondence list. Among other data, I also store the post tracking number there:



For this list I implemented 2 business processes: The first one is a simple one that allows me to quickly check the tracking number manually and receive data in private messages in the portal:


The only action that this business process performs is calling a webhook.


The handler of this webhook on the AWS Lambda side looks like this: I run this business process manually:


After that, I receive a personal message with the entire history of moving the letter and its current status:


The second - a large business process starts automatically when the list entry is changed:


The business process checks are in this letter, incoming or outgoing. For incoming, it does nothing. Tracking number for an outgoing letter doesn’t appear immediately because I enter an entry in the list when I pack documents into an envelope, and I fill the tracking number later when I receive mail receipts, so the business process checks to see if tracking number already exists and if not yet - it waits for 3 days. If the tracking number already exists, the business process calls the webhook.


Its handler is similar to the one I have already shown, but also the status is being recorded in the "Status" field of the list. How to update the list from the AWS Lambda function, I also wrote earlier in the blog: http://bedrosovayulia.blogspot.com/2019/07/how-to-update-bitrix24-list-item-in.html

After calling the webhook, I inserted into the business process a pause of 5 minutes to give the handler on the AWS Lambda side time to process. After this, the business process checks whether the tracking number has moved to the final status "Delivered" - if yes, then the cycle stops spinning. If the status is not reached, then after 3 days the process is repeated. This process works on its own and frees me from routine work.


All I need in order to see the status of my sent letters are to go to my list and set the necessary filters. Similarly, it is possible to integrate the cloud Bitrix24 with any external system that can give data via SOAP or provides API in any form.

Comments

Popular posts from this blog

How to add a custom activity type in Bitrix24 CRM

During one of our recent self-hosted Bitrix24 implementations, we had the task of adding a new type of Activity to CRM - something between a Call Activity and a Visit Activity. The customer wanted this new Activity to be able to participate in CRM reports and filters. To begin with, it was necessary to add a link to a new Activity type in the CRM entity card. We found out that the crm.timeline component is responsible for the output of this part of the interface. In particular, its template.php contains a list of displayed links to case types. For example, for a call, something like: Accordingly, as we can see, this is a regular link with the data parameter item-item-id. So we can add ours, with our own unique data-item-id. As you can see, the href for the link is set as "#" - clicking on this link is processed by the JS code from the script.js of this component. Indeed, the BX.CrmTimelineMenuBar function is responsible for this.processItemSelection().

How to setup server for Bitrix24 on AWS EC2

How to сreate AWS Lambda Layer with Zeep Library

Python Zeep library designed to work with SOAP - services. Zeep is a pure-python module. However the lxml dependency does contain C code since it uses libxml2 and libxslt. So the Zeep library can not be deployed into the Lambda Layer without some tricks. In one of my Serverless projects, I needed to use this library, and I found such a way to deploy it into the Layer: