How did we build a transaction approval bot in Slack?
We often spend a lot of time approving transactions for grocery purchases, salary processing, etc. This is how our approval process was before we develop this Approval Bot.
- The admin team will raise a support ticket for fund
- The financial team will review and approves it
- Once the ticket got approved then the admin team will initiate the transactions and waits for One-Time Password (OTP) that to be shared from the financial team
- After they receive OTP they successfully complete the transactions
By doing so our entire productive hour goes into vain if someone missed support ticket notification or forgot to share the OTP and the cycle repeats. Our primary communicating medium is Slack we decided to connect Slack with our Approval Bot to replace the manual approval flow so that we can improve our productive hours.
Our confident approach was to extract OTP from the email body or PDF. With the help of Internet Message Access Protocol (IMAP), our bot watches all incoming emails and filter further using email subject, sender, or receiver. After getting the email body/PDF by playing around with RegExp it extracts From, To, Amount & OTP then the confidential part OTP is masked and posted it to Slack channel where both Admin & Financial team will be a member. Once the financial team approves it OTP is unmasked and the admin team process the transaction successfully.
Code snippet to parse an incoming email
OTP will be in either an email body or PDF. If it is in PDf then our bot will download the attachment from the email and parse it with the help of the below-mentioned library. If it is in email body bot just parse its content.
RegExp to extract details that we needed
This is the sample regular expression that we can tweak to extract any details we need.
const beneficiaryRegExp = new RegExp(/(?<beneficiary>(?<=\d\sto\s).*(?=\sis))/);const otpRegExp = new RegExp(/(?<otp>\d{6,8})/);const amountRegExp = new RegExp(/(?:Rs\.?|INR)\s*(\d+(?:[.,]\d+)*)|(\d+(?:[.,]\d+)*)\s*(?:Rs\.?|INR)/);