How can we remove the command from Telegram Trigger using Function Node

How can we remove the word “/movie” using Function Node?

From the Telegram bot, we can’t trigger the bot without calling /command. In my case… It’s called “/movie”.
This way the command also sends into HTTP Request Node to search for the keyword “asuran”.

I’m trying to avoid that. You can clearly see that in the below chat screenshot.

And more matter it’s “/movie” or “/Movie” telegram will convert into “/movie

Selection_257

For that you should really google how you can do it with JavaScript. Because all you are doing in the Function-Node is to execute JavaScript code. So checking out the JavaScript basics is probably a good idea.

As an external person does your question raises simply more questions which makes answering impossible. For example is it always “/Movie” like in your text or is it actually “/movie” like in your example? Is it always exactly that word or could be be any? Is it always the first word or could it be also the second, third, …? What happens if there are multiple ones with a slash in front of it, should it remove all of them or only the first one? What if there is a space between the slash and the word? …?

Making now a lot of assumptions like that the slash does actually not matter at all and all you want to do is simply always remove the very first word, the code would look like this:

'/movie asuran'.split(' ').slice(1).join(' ')

(This answer was written before the question got updated)

2 Likes

Thanks, @jan for your reply. I updated the Question more specifically for a better understanding of the use case.

And I tried this code in the Function node.

let trim = '{{$node["Telegram Trigger"].json["message"]["text"]}}';
items[0].json.myVariable = trim.replace("/movie", "");
return items;

You are using expression-syntax {{ }} in a Function-Node. That will not work. What you want is something like this.

let text = $node["Telegram Trigger"].json["message"]["text"];
items[0].json.movieName = text.trim().split(' ').slice(1).filter(data => !!data).join(' ');
return items;

Thanks @jan It works.