Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
BotBuilder Engine
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Yauheni Hlazkou
BotBuilder Engine
Merge requests
!6
Feature/base telegram text bot
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Feature/base telegram text bot
feature/base-telegram-text-bot
into
develop
Overview
0
Commits
5
Pipelines
0
Changes
12
Merged
Oleksandr Petrov
requested to merge
feature/base-telegram-text-bot
into
develop
2 years ago
Overview
0
Commits
5
Pipelines
0
Changes
12
Expand
@all
take a look
1
0
Merge request reports
Compare
develop
develop (base)
and
latest version
latest version
44816b18
5 commits,
2 years ago
12 files
+
273
−
3
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
12
Search (e.g. *.vue) (Ctrl+P)
api/src/main/java/cz/cvut/fit/sp/bot_builder/text_bot/BaseTextBotHandler.java
0 → 100644
+
44
−
0
Options
package
cz.cvut.fit.sp.bot_builder.text_bot
;
import
cz.cvut.fit.base.bot_builder.base.base_bot.BaseTextHandlerInterface
;
import
cz.cvut.fit.base.bot_builder.base.base_bot.ChatBotTextAnswer
;
import
cz.cvut.fit.base.bot_builder.base.base_bot.UserRequest
;
import
lombok.Getter
;
import
lombok.NonNull
;
import
lombok.RequiredArgsConstructor
;
import
lombok.Setter
;
import
org.telegram.telegrambots.meta.api.methods.send.SendMessage
;
import
org.telegram.telegrambots.meta.api.objects.Message
;
import
java.util.Map
;
import
java.util.Optional
;
@Getter
@Setter
@RequiredArgsConstructor
public
class
BaseTextBotHandler
implements
BaseTextHandlerInterface
{
@NonNull
private
Map
<
UserRequest
,
ChatBotTextAnswer
>
botCommands
;
@Override
public
Optional
<
SendMessage
>
executeRequest
(
String
chatId
,
String
username
,
Message
message
)
{
// Try to find user request in available requests list
Optional
<
Map
.
Entry
<
UserRequest
,
ChatBotTextAnswer
>>
request
=
botCommands
.
entrySet
()
.
stream
()
.
filter
((
req
)
->
req
.
getKey
().
equals
(
new
UserRequest
(
message
.
getText
()))).
findFirst
();
if
(
request
.
isEmpty
())
{
// Request not found...
return
Optional
.
empty
();
}
return
produceAnswer
(
request
.
get
(),
chatId
);
}
@Override
public
Optional
<
SendMessage
>
produceAnswer
(
Map
.
Entry
<
UserRequest
,
ChatBotTextAnswer
>
requestOptional
,
String
chatId
)
{
return
Optional
.
ofNullable
(
requestOptional
.
getValue
().
convertToMessage
(
chatId
));
}
}
Loading