Reputation: 21
Disclaimer I am a newbie at programing and also not really good at english, so please pardon my bad explanation.
My bot had to send a message containing data retrieved from a spreadsheet, but found that the data was so many that it exceeded the character limit of the telegram message (4096 characters).
So I assume that I have to split the message, then send them in sequence. Please help...
here's my code :
function SearchbyProjectName(Prjct){
var projectNON = GetAllProjectNON();
var project = GetAllProject();
var num = 1;
const allLocation = [];
var header =
'xxxheaderxxx';
var footer =
'xxxfooterxxx'
for (var row=0; row<projectNON.length; row++) {
if(projectNON[row][3]==Prjct){
var resiNON = num++ + '. ) ' + '/d_' + projectNON[row][6] + '\n\n';
allLocation.push(resiNON);
}
}
for (var row=0; row<project.length; row++) {
if(project[row][3]==Prjct){
var resi = num++ + '. ) ' + '/d_' + project[row][6] + '\n\n';
allLocation.push(resi);
}
}
var stringg = allLocation.toString();
var clearComma = stringg.replaceAll(",", "")
var newData = header + clearComma + footer;
return newData ;
}
here's the message :
ALL LOCATION Project: PTT2 š : Tuesday, 24 Jan 2023 15:10:34
) /d_XXXXXXXXXXX
) /d_XXXXXXXXXXXXX
) /d_XXXX
) /d_DDDDDD
) /d_JJJJJJJJJJJJJ
) /d_XXXXXXX
...
I wish I could split the message at number 100.)
Upvotes: 0
Views: 708
Reputation: 8606
I'm not able to test this but I think it might solve your problem. For every 100 projects store the string in the array newData
. Then in the receiver of newData
loop throught the array of strings and send each individually.
Notice I don't push strings to the array allLocation
but simply concatinate strings. Once I've reach a multiple of 100 push that concatinated string to the array newData
.
function SearchbyProjectName(Prjct){
var projectNON = GetAllProjectNON();
var project = GetAllProject();
var num = 1;
var newData = [];
var allLocation = "xxxheaderxxx";
var footer = "xxxfooterxxx";
var limit = 100;
for (var row=0; row<projectNON.length; row++) {
if(projectNON[row][3]==Prjct){
var resiNON = num++ + '. ) ' + '/d_' + projectNON[row][6] + '\n\n';
allLocation.concat(resiNON);
if( num === limit ) {
newData.push(allLocation);
limit = limit+100;
allLocation = "";
}
}
}
for (var row=0; row<project.length; row++) {
if(project[row][3]==Prjct){
var resi = num++ + '. ) ' + '/d_' + project[row][6] + '\n\n';
allLocation.concat(resi);
if( num === limit ) {
newData.push(allLocation);
limit = limit+100;
allLocation = "";
}
}
}
allLocation = allLocation.concat(footer);
newData.push(allLocation);
return newData;
}
Reference
Upvotes: 1