TypeError: key.startsWith is not a function

Getting this error for function,
"TypeError: key.startsWith is not a function" and I don't know what happens. Can anyone help me to solve this problem. Here is my code in the function.

msg.chatId= msg.payload.chatId;
if (msg.payload.type === "voice"){
return [null, msg,null];

msg.payload = msg.payload.content;
msg.transcription = msg.payload;

if (msg.payload === "RestLang"|| msg.payload === "/start" ){
msg.payloadtran= "test1";
msg.payload = "Welcome to Translator Bot!! \nTranslator Bot is a translation app used IBM services to make the translation smart and easy. \n In this version you can use translation in the following: \n- Arabic to English\n- English to Arabic\n- Spanish to English\n- French to English\n- Japanese to English\nand we will support more language in the future.\nTo start the translation try to say \nHello, مرحبا, Hola, Bonjour, こんにちは \nby your voice to set the default language. \nor type anything in the supported language and the app will identify the language then translate it. ";
return [null,null, msg];

return [msg,null,null];

Welcome to the forum.

Are you sure the error is coming from that function? Give the function node a name, if it does not already have a name, then it will be identified with the error. Alternatively you can use the Search feature to search for the node id (the string of characters with a dot in the middle).

Can you share (i.e. export) a "simple" flow with a function node, and an inject node (which injects an example message that causes the error). That makes it easy for us to help people.

BTW if you need to implement multiple function nodes, it might be worth to learn debugging your function node code. You can do that very easily as described here.


For debugging simple function nodes I find it is usually enough just to use node.warn() as described in the docs for Writing Functions. For more complex issues then the technique linked above is a good way to go.

Sorry i don't understand. You mean the screenshot of my flow and code?

Not use either the function or not. But the debug error shown in the function.

Please fill in the Name field for the function and show us what appears in the debug.

I think this is happening because msg.chatId is not a string, and global.set expects a string as the first argument.

You'd have to pass a message to Debug to see exactly what it is, but my guess is it's a number.

You could try forcing it to a string with:

1 Like

Got it. Thank you so much. Error solved!