From 3414d8c9f54f1dd22e9b54481be78e7e002338bc Mon Sep 17 00:00:00 2001 From: Abbas Abou Daya Date: Mon, 30 Oct 2017 21:45:08 -0400 Subject: [PATCH] Added advanced use case FAQ --- TelegramBots.wiki/_Sidebar.md | 1 + TelegramBots.wiki/abilities/Advanced.md | 39 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 TelegramBots.wiki/abilities/Advanced.md diff --git a/TelegramBots.wiki/_Sidebar.md b/TelegramBots.wiki/_Sidebar.md index 52339f4f..fc7b47b2 100644 --- a/TelegramBots.wiki/_Sidebar.md +++ b/TelegramBots.wiki/_Sidebar.md @@ -9,5 +9,6 @@ * [[Database Handling]] * [[Bot Testing]] * [[Bot Recovery]] + * [[Advanced]] * [[Changelog]] * [[How To Update]] \ No newline at end of file diff --git a/TelegramBots.wiki/abilities/Advanced.md b/TelegramBots.wiki/abilities/Advanced.md new file mode 100644 index 00000000..39189c36 --- /dev/null +++ b/TelegramBots.wiki/abilities/Advanced.md @@ -0,0 +1,39 @@ +# Advanced +This will be more of a FAQ on some important notes before you embark on your next big bot project! + +## Default Abilties + +It is possible to declare "DEFAULT" abilities that process non-command messages. This is quite close to a reply. If a user says "Hey there" and the default ability is implemented, it will process this input. +```java + /** + * This ability has an extra "flag". It needs a photo to activate! This feature is activated by default if there is no /command given. + */ + public Ability sayNiceToPhoto() { + return Ability.builder() + .name(DEFAULT) // DEFAULT ability is executed if user did not specify a command -> Bot needs to have access to messages (check FatherBot) + .flag(PHOTO) + .privacy(PUBLIC) + .locality(ALL) + .input(0) + .action(ctx -> silent.send("Daaaaang, what a nice photo!", ctx.chatId())) + .build(); + } +``` + +This ability will send a *"Daaaaang, what a nice photo!"* whenever the bot receives a photo. This is one use case where replies and abilities are interchangeable. + +## The Global Flag +However, there is one important note here. This ability without any additional code will not be able to process photos. There is a global flag in AbilityBot that restricts the kind of "updates" it can process. +To freely process any update given to your bot, make sure to: + +```java +/** + * By default, any update that does not have a message will not pass through abilities. + * To customize that, you can just override this global flag and make it return true at every update. + * This way, the ability flags will be the only ones responsible for checking the update's validity. + */ + @Override + public boolean checkGlobalFlags(Update update) { + return true; + } +``` \ No newline at end of file