User
#struct UserOne Telegram user.
| Name | Type | Description |
|---|---|---|
id | i64 = 0 | The id. |
is_bot | bool = false | It is a bot. |
first_name | str = "" | The first name. |
last_name | str = "" | The last name. |
username | str = "" | The user name. |
language_code | str = "" | The language of the user, such as fa. |
import telegram.bot
func main:
text := `{"update_id":10,"message":{"message_id":5,"date":1700000000,"text":"/start hello","chat":{"id":42,"type":"private","first_name":"Maryam","username":"maryam"},"from":{"id":42,"is_bot":false,"first_name":"Maryam","language_code":"en"},"reply_to_message":{"message_id":4,"from":{"id":7,"first_name":"Ali"}}}}`
update := bot.ParseUpdate(text)
println update.update_id, update.has_message, update.has_callback_query
m := update.message
println m.message_id,
m.date,
m.text,
m.chat.id,
m.chat.chat_type,
m.chat.first_name,
m.chat.username
println m.from_user.id,
m.from_user.is_bot,
m.from_user.language_code,
m.reply_to.message_id,
m.reply_to.user_id,
m.reply_to.user_name
println bot.IsCommand(m.text), bot.CommandName(m.text), bot.CommandArgs(m.text)
println bot.IsCommand("hello"), bot.CommandName("/help@my_bot")
all := bot.ParseUpdates(
`{"ok":true,"result":[{"update_id":11,"callback_query":{"id":"cq1","data":"yes","from":{"id":42,"first_name":"Maryam"},"message":{"message_id":9,"chat":{"id":42,"type":"private"}}}},{"update_id":12,"inline_query":{"id":"iq1","query":"book","offset":"","from":{"id":42,"first_name":"Maryam"}}}]}`
)
println all.Len()
q := all[0].callback_query
println all[0].has_callback_query,
q.id,
q.data,
q.from_user.first_name,
q.has_message,
q.message.message_id
typed := all[1].inline_query
println all[1].has_inline_query, typed.id, typed.query, typed.offset.Len()
println bot.ParseUser(`{"id":1,"first_name":"x","last_name":"y","is_bot":true}`).last_name
println bot.ParseChat(`{"id":-100,"type":"supergroup","title":"the group"}`).title
println bot.ParseMessage(`{"message_id":1,"caption":"a photo","chat":{"id":1}}`).caption
println bot.ParseCallbackQuery(`{"id":"q","data":"d"}`).data,
bot.ParseInlineQuery(`{"id":"i","query":"q"}`).query
println bot.ParseUpdate(
`{"update_id":13,"channel_post":{"message_id":1,"text":"news","chat":{"id":-5}}}`
).channel_post.text
mut row1 := Vector {} as Vector<str>
row1.Push(bot.InlineButton("yes", "yes"))
row1.Push(bot.InlineButton("no", "no"))
mut row2 := Vector {} as Vector<str>
row2.Push(
bot.InlineButtonURL("the site", "https://salamlang.ir")
)
mut rows := Vector {} as Vector<str>
rows.Push(bot.Row(row1))
rows.Push(bot.Row(row2))
println bot.InlineKeyboardMarkup(rows)
mut plain := Vector {} as Vector<str>
plain.Push(bot.KeyboardButton("menu"))
mut plain_rows := Vector {} as Vector<str>
plain_rows.Push(bot.Row(plain))
println bot.ReplyKeyboardMarkup(plain_rows)
println bot.RemoveKeyboard(), bot.ForceReply()
println bot.BotCommand("start", "start it")
robot := bot.NewBot("123:ABC")
println bot.FileURL(robot, "photos/file_1.jpg")
println bot.ReplyMessage(42, "hello")
mut options := bot.SendOptions {}
options.parse_mode = "HTML"
options.reply_to_message_id = 5
options.disable_notification = true
println bot.ReplyMessageOptions(42, "<b>hello</b>", options)
println bot.ReplyAnswerCallbackQuery("cq1", "noted", false)
println bot.ReplyChatAction(42, "typing")
println bot.ReplyEditMessageText(42, 9, "updated", bot.RemoveKeyboard())
println bot.SECRET_HEADER
end