[Urgent] Auto generate chat id at the beginning of bot journey

Hi,

I want to auto generate an alphanumeric key in the code section (cloud function). Can you please help me how to do it? What is the function that will randomly generate that? It will serve as a unique chat id for me.

Also, how can I concatenate a string and a number inside a cloud function?

1 Like

You can write a function in Node.js as shown below:

function guidGenerator() {
    var S4 = function() {
       return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
    };
    return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}

Source: javascript - generate random string for div id - Stack Overflow

Talking about concat operation of a string and a number, you can simply use the addition operator.