Skip to content

Frequently Asked Questions

Sahri Riza Umami edited this page Jan 13, 2017 · 8 revisions

Why I always get 1484111513.000000 lua: attempt to call a nil value? The number always different and the functions are works.

You're missing a global callback function.
Please create a global callback function on your script, even if it's just an empty one.

Example, for a getMessage function and its patternsByReply custom callback:

tdcli.getMessage(msg.chat_id_, msg.reply_to_message_id_, patternsByReply, {
                 chat_id = msg.chat_id_,
                 text = msg.content_.text_
})

Create a global callback function:

function patternsByReply(arg, data)
end

Why the function parameters are so long?

tdcli.lua meant to be a universal library. So, every parameter counts.
Just create a custom function as an alias to make it shorter and more fitted to your script.

Example, this is a default to send a text message:

tdcli.sendText(msg.chat_id_, msg.id_, 0, 1, nil, text, 1, 'HTML', dl_cb, cmd)

But, you're rarely use parameters other than chat_id, msg_id, and text. Create a function like this:

function sendText(chat_id, reply_to_message_id, text, disable_web_page_preview, parse_mode)
  local parse_mode = parse_mode or 'HTML'
  local disable_web_page_preview = disable_web_page_preview or 1
  tdcli.sendText(chat_id, reply_to_message_id, 0, 1, nil, text, disable_web_page_preview, parse_mode)
end

So, next time you need to send a text message, you just need to type:

sendText(msg.chat_id_, msg.id_, "Hi, it's me")

Test script
Frequently Asked Questions
The Functions

Clone this wiki locally