Pictobot.core¶
Pictobot is a Telegram Bot, that is, a conversational program. It is designed to help you communicate while you are traveling abroad.
-
pictobot.core.
browse
(bot, update)¶ /browse command. Displays a keyboard/buttons UI for navigation.
Catalog-like UI where the user can browse through different categories of pictograms.
- Parameters
bot (object) – the bot instance.
update (object) – the message sent by the user.
-
pictobot.core.
build_keyboard
(kb_dict)¶ Builds a keyboard/buttons object from a dict
- Parameters
kbdict (dict) – dict of buttons to display on the keyboard
- Returns
A keyboard formated for Telegram (InlineKeyboardMarkup)
- Return type
object
-
pictobot.core.
cmd_search
(bot, update, args)¶ _/search_ command
User typed /search command. Either with some search query behind it. Or without any text, in which case we ask her/him to type his/her query.
- Parameters
bot – (object) the bot instance.
update – (object) the message sent by the user.
args – (list) search query typed by the user.
-
pictobot.core.
dispatch
(bot, update)¶ Handling of callbacks from inline keyboards
Either send back another keyboard, a pictogram, or an error message
- Parameters
bot (object) – the bot instance.
update (object) – the message sent by the user.
-
pictobot.core.
error
(bot, update, error)¶ Logs errors.
-
pictobot.core.
fuzzy_search
(query, limit=7)¶ Fuzzy search the dict containing the search keywords
Return best results sorted by score, descending.
- Parameters
query (string) – the user’s search strings.
limit (int) – number of results to return.
- Returns
A list of results sorted by score and simple_ratio(fuzz.ratio)
- Return type
list
-
pictobot.core.
help
(bot, update)¶ /help command. Displays help message to the user.
The user either used the /help command or is being sent here after getting lost. A helpful message is displayed, and a reminder button that the inline query mode is available.
- Parameters
bot (object) – the bot instance.
update (object) – the message sent by the user.
-
pictobot.core.
inline_search
(bot, update)¶ Inline search function: called everytime the user types a character.
This type of search is only functionning when the image folders are on a web server, Telegram expects proper URLs.
- Parameters
bot (object) – the bot instance.
update (object) – the message sent by the user.
-
pictobot.core.
main
()¶ Declaring handlers, start polling or webhook.
-
pictobot.core.
quick_search
(bot, update)¶ User types his/her query directly (no command)
User being rerouted to classic search function, it’s just a wrapper really.
- Parameters
bot – (object) the bot instance.
update – (object) the message sent by the user.
-
pictobot.core.
sanitize_string
(query)¶ Clean up user input
Remove unwanted characters from strings and convert uppercase caharacters before search: for better scores on Levenshtein distances.
- Parameters
query (string) – the user’s search strings.
- Returns
A sanitized string.
- Return type
string
-
pictobot.core.
search
(bot, update, raw_query)¶ Search function
Clean up the search query via sanitize_string function, get results from fuzzy_search function. Either return results as a keyboard or display a “not found” message.
- Parameters
bot (object) – the bot instance.
update (object) – the message sent by the user.
raw_query (list) – search query typed by the user.
-
pictobot.core.
send_picto
(bot, chat_id, text)¶ Sends a pictogram to the user.
- Parameters
bot (object) – the bot instance.
chat_id (str) – the id of the chat where the picto must be sent.
text (str) – the key of the dict corresponding to the picto to send.
-
pictobot.core.
settings
(bot, update)¶ /settings command. Not implemented yet. Not advertised to BotFather either.
Displays a joke message if anyone ever tries this command until it’s implemented.
- Parameters
bot (object) – the bot instance.
update (object) – the message sent by the user.
-
pictobot.core.
start
(bot, update, args)¶ /start command. Displays welcome message.
Displays a welcome message and a help message (via a triggered /help command). If the user is sent here after an unsuccessful inline search a hopefully helpful message is shown.
- Parameters
bot (object) – the bot instance.
update (object) – the message sent by the user.
args (tuple) – search terms.
-
pictobot.core.
unknown_command
(bot, update)¶ Where the unknown commands come to die.
- Parameters
bot (object) – the bot instance.
update (object) – the message sent by the user.
-
pictobot.core.
unknown_type
(bot, update)¶ Unknown -Telegram- type handler.
The bot only accepts text input. If any other data type is sent, it is rejected.
- Parameters
bot (object) – the bot instance.
update (object) – the message sent by the user.