How to dynamically reset custom fields and tabs in ManyChat
When I test flows and scenarios as I build a messenger bot, I end up with far more tags and custom user fields (CUFs) than I’ll ever need. The sanity challenge comes in during testing.
There was a time I would spend more time attempting to determine whether or not I was bug-fixing a real problem or dealing with a holdover from a tag or CUF from a previous test or flow that was just getting in the way.
Finally I couldn’t take it anymore so I built a process. It starts with a quick message that kicks off a scenario in Integromat.
That was version 0.5 — it worked. I basically copied in the list of custom fields (List #1) and tags (List #2) finto a google sheet and used Integromat to loop through the two lists and use the API to either “null” them or clear them outright. I nicknamed this version “Brute Force.”
“Brute Force” had two challenges: (1) maintenance and (2) processing expense. Whenever a new tag was added or removed or when a new custom field was added or removed, one had to manually update the Google Sheet.
The second challenge was processing expense. I discount this concern slightly because this tool is just for testers — this process ran about 270 operations — whether we had the field or tag attached to our profile or not.
But it worked. And I got a lot more done. It was also great for clients who wanted to test things — especially the ones who retested part of a flow and complained when they went to the very beginning and experienced intermittent behavior
So this weekend, I set out to write it all up here — step by step — all 22 pages of it. But, as I reviewed my masterpiece, the phrases, “over-complicated” and “excruciating” kept coming to mind. I began to wonder,
“How could I run a process that would only (dynamically) grab just the CUFs and tags that a subscriber actually had associated with their account?”
Version 1.0 was born based upon this operating theory
Instead of looking up 180+ fields and 80+ tags every time, this time I was going to run a quick check on the subscriber to determine what CUFs and Tags they actually had associated with their account. Using the ManyChat API documentation for this topic I called the “Get Subscriber Info” endpoint via a GET request.
For us non-devs, I made it so Integromat could pull the information about a subscriber — using their ID.
Working with no more than what I needed, I could — once I sorted the rest of it out — refresh almost any account to it’s “just off the street” state.
Note: I am describing my most basic version of this — I added bells, whistles and a complete download for the people in my FB group. Most of it is here — I wouldn’t pull a bait and switch this early in the story.
In version 0.5 I was reading the data out of a Google Sheet. In this version, I wanted to read it and clear it on the fly. No Google Sheet. That meant that I had to find a tool in the Integromat stack to pick apart the JSON response that came back from ManyChat.
I used “Parse JSON.”
This module takes the JSON response from the GET request and creates a model from which the downstream models can consistently extract the right data about CUFs and Tags.
Once the JSON was parsed and modeled, I was able to identify two sets of arrays, one containing the CUFs, the other Tags.
Once I had those two groups identified, I built calls to the ManyChat API (this time it was a POST call)
The first was to null the Custom Fields. For that I used the the Set Custom Field by Name ManyChat endpoint. We used “null” because our research showed we could not send in a blank field.
Next was to unset the Tags we identified dynamically. To do that, the Remove Tag By Name ManyChat endpoint was used. The body of that API call was similar, but slightly different.
Because they were arrays that could hold more than one tag or custom field and I was only able to run one API call at a time, I needed a method to “loop” through all our “found” CUFs and Tags and send them one by one in to be cleared.
For that, I used another native Integromat tool, the Iterator. It allowed me to point to a single array — with the understanding that it would read through every item in the array until there were no more CUFs or Tags to be processed for a particular subscriber.
Another iterator was used on the Tag arrays. In my case, te iterator is placed after the “Parse JSON” module and before the POST API call — that cleans the subscriber CUFs and Tags.
The process goes a bit like this:
A button is clicked or tapped in a ManyChat flow. That button triggers an action that calls an Integromat webhook. That webhook triggers a GET request to identify the subscriber’s CUFs and Tags.
Integromat’s Parse JSON module allows us to model the output from the GET request and two iterators are assigned to loop through the CUF and Tag arrays, separately. After each iterator, a POST API call is made to ManyChat (via its API) that will clear out any CUF associated with the subscriber and unset any Tag associated with that same subscriber.
Once I put this together the run-time for my “clean” process was reduced to 7 seconds from 27 seconds, using 16 processes instead of 270.
Why in the world would you ever use this?
- If you have conditional logic using tags or fields you haven’t fixed just yet — this is for you
- If you have a ton of custom fields and tags, this is for you.
- If you just like to start clean every time — this is for you.
- If you do demos this is for you
- If you ever had an eager client try and test something before you had time to clean things for them — and you’ve spent a day building their confidence back up after it bombs, this is for you
- You don’t want to use my 22-page version of this process using Google Sheets
I’m looking to build more and more of these pieces — sharing my learnings with you. You should check me out and find my Integromat Group. Connect (full disclosure its paid) — I love finding out better ways of doing things and there’s no other better way than helping people solve their problems!