How to split and post several messages without exceeding a certain character limit. e.g Discord
If you use Discord then you know that when posting a message it has a 2000 character limit. Also according to https://discord.com/developers/docs/resources/webhook#execute-webhook, the maximum is 2000 and you can not bypass it according to the API documentation. So then the question comes as to how can you split a single message into several messages and then have that posted in one scenario run?
In comes the power of Integromat!
We will take a use case of whereby you would like to reply to a user from your Gmail and send that information to Discord. Below is how the scenario overall look should be like.
Compile the message in the Set variable module "Message to be sent" in whichever way you would like an example can be seen below
Then use another set variable module which we will name "Counter", the sole purpose of this module is to count how many characters are in your text. To be able to do that you will need to use the length function as shown below you can find that in the text and binary functions segment.
Then we will need to use again another set variable module that we help in getting the 1st result, the result 1 module will check if the characters are less than 2000 and if so it will automatically capture the "Message to be sent" as is. If it is not it will then cut "Message to be sent" up to 2000 characters which is the limit for Discord with the aid of the substring function that can be found under the text and binary functions segment.
Once that is done then we move on to Result 2, this set variable is almost similar to Result 1 module but differs in that, this module is now looking for characters that are above 2000 and below 4000. The principle used in the if function is also different. Here you can see and compare that we are checking if the counter has values that are greater than 2000 and if not it will ignore if so then it will place the characters that are between 2000 and 4000.
Once the above has been set up let's go to the repeater module. This module will distinguish whether we should repeat the data or not. So we employ the use of the if function, here what we are doing is checking if the counter is less than 2000 and if so then it will only generate a single bundle that means that the scenario will not repeat anything as it will only run just once and if it is more than 2000 then it will generate two bundles therefore that will cause the next module to run twice.
Now on to the final part of this setup. This is the tricky part, how do you get the scenario to purposefully generate new content when the repeater module activates it and the data has to be different and consecutive? Integromat allows you to manipulate data and the possibilities are almost endless. This data has been manipulated from the very first set variable module we used in the scenario.
Now back to this Discord module we deploy the if function in a strategical manner. What we have done below is to state that if the counter is less than 2000 then let's post the message as it is. But if the counter is more than 2000 it must post the next thing. So we then deployed what we call "nested functions" as you can see we used the if function again and we stated that if the repeater module value is equal to 2 then place Result 2 if not place Result 1, the reason for this is that we purposefully know that the repeater module will start with a value of 1 and then the next bundle will be 2. So the 1st bundle will generate a false and therefore the result will be just as you guessed it Result 1. When its bundle 2 it will generate a true and the result will be Result 2.
And there you have it the 1st operation will have the 1st part of the message sent to Discord and then the 2nd operation will have the last part of the message. You will have successfully managed to split and post multiple messages without exceeding the character limit. This principle can be used not only in Discord but also on Twitter or any other app that has such limitations.