params¶
Whatever the user typed after your command — the arguments, the query, the extra words.
What is it?¶
params is a string containing the text that comes after a command name. If someone sends /start hello world, the command is /start and params is "hello world".
No parsing magic, no JSON, no key-value pairs. Just a string you can read, split, or validate. Simple on purpose.
When would you use it?¶
- Commands that take user input:
/search cats,/greet Alice,/calc 2+2 - Quick argument checks before doing work
- Webhook endpoints where query or body values map to
params
For structured data (objects with multiple fields), consider options via Bot.run instead. For the full message text (not just post-command args), see message.
Try it¶
// /greet Alice
if (params) {
Bot.sendMessage("Hello, " + params + "!")
} else {
Bot.sendMessage("Usage: /greet <name>")
}
// /search something
if (!params) {
return Bot.sendMessage("Usage: /search <query>")
}
Bot.sendMessage("Searching for: " + params)
Where params comes from¶
Telegram commands¶
| User sends | Command | params |
|---|---|---|
/start | /start | "" (empty string) |
/start hello world | /start | "hello world" |
/greet Alice | /greet | "Alice" |
The command name itself is not included in params.
Webhooks and webapps¶
In Webhook and Webapp mode, params may come from URL query parameters or the request body:
See also request for full HTTP request access.
Parsing multiple arguments¶
params is one string. Split it yourself if you need separate values:
let args = params.split(" ")
let action = args[0]
let value = args[1]
if (!action) {
return Bot.sendMessage("Usage: /do <action> <value>")
}
For anything more complex than space-separated words, pass an object through options instead.