1- package io .notifye .botengine .client .action .controller ;
2-
3- import java .util .ArrayList ;
4- import java .util .List ;
5- import java .util .concurrent .CopyOnWriteArrayList ;
6-
7- import io .notifye .botengine .client .Engine ;
8- import io .notifye .botengine .client .Token ;
9- import io .notifye .botengine .client .action .InteractionAction ;
10- import io .notifye .botengine .client .bots .Bot ;
11- import io .notifye .botengine .client .model .Interaction ;
12- import io .notifye .botengine .client .model .enums .InteractionType ;
13- import lombok .extern .slf4j .Slf4j ;
14-
15- @ Slf4j
16- public final class InteractionsActionController implements InteractionAction {
17-
18- private static final long serialVersionUID = 1L ;
19-
20- private final String ACTION_NAME = InteractionAction .class .getSimpleName ();
21-
22- private final Bot bot ;
23- private final Token token ;
24- private List <Interaction > interactions ;
25-
26- public InteractionsActionController (final Bot bot , final Token token ) {
27- super ();
28- this .bot = bot ;
29- this .token = token ;
30- }
31-
32- public List <Interaction > getInteractions (){
33- return this .interactions ;
34- }
35-
36- @ Override
37- public InteractionAction add () {
38- this .interactions = new CopyOnWriteArrayList <Interaction >(new ArrayList <Interaction >());
39- return this ;
40- }
41-
42- @ Override
43- public InteractionAction welcome (Interaction welcomeInteraction ) {
44- welcomeInteraction .setType (InteractionType .welcome );
45- this .interactions .add (welcomeInteraction );
46- return this ;
47- }
48-
49- @ Override
50- public InteractionAction fallback (Interaction fallbackInteraction ) {
51- fallbackInteraction .setType (InteractionType .fallback );
52- this .interactions .add (fallbackInteraction );
53- return this ;
54- }
55-
56- @ Override
57- public InteractionAction interaction (Interaction userInteraction ) {
58- userInteraction .setType (InteractionType .user );
59- this .interactions .add (userInteraction );
60- return this ;
61- }
62-
63- @ Override
64- public Bot build () {
65-
66- this .interactions .stream ()
67- .forEach (interaction -> {
68- log .info ("Creating Entities..." );
69-
70- if (interaction .getEntities () != null && interaction .getEntities ().size () > 0 ){
71- interaction .getEntities ().forEach (entity -> {
72- Engine .createEntity (entity , this .token );
73- });
74- }
75- //CREATE INTERACTION
76- log .info ("Creating Interaction -> {}" , interaction );
77- Engine .creatInteraction (this .bot .getStory (), interaction , this .token );
78- });
79-
80- return this .bot ;
81- }
82-
83- @ Override
84- public String getActionName () {
85- return ACTION_NAME ;
86- }
87-
88- @ Override
89- public int getOrderExecution () {
90- return 0 ;
91- }
92-
93- public Token getToken () {
94- return token ;
95- }
96-
97-
98-
1+ package io .notifye .botengine .client .action .controller ;
2+
3+ import java .util .ArrayList ;
4+ import java .util .List ;
5+ import java .util .Objects ;
6+ import java .util .concurrent .CopyOnWriteArrayList ;
7+
8+ import io .notifye .botengine .client .Engine ;
9+ import io .notifye .botengine .client .Token ;
10+ import io .notifye .botengine .client .action .InteractionAction ;
11+ import io .notifye .botengine .client .bots .Bot ;
12+ import io .notifye .botengine .client .model .Interaction ;
13+ import io .notifye .botengine .client .model .enums .InteractionType ;
14+ import lombok .Data ;
15+ import lombok .RequiredArgsConstructor ;
16+ import lombok .extern .slf4j .Slf4j ;
17+
18+ @ Slf4j
19+ @ RequiredArgsConstructor
20+ public final @ Data class InteractionsActionController implements InteractionAction {
21+ private static final long serialVersionUID = 1L ;
22+ private final String ACTION_NAME = InteractionAction .class .getSimpleName ();
23+
24+ private final Bot bot ;
25+ private final Token token ;
26+ private List <Interaction > interactions ;
27+
28+ public List <Interaction > getInteractions (){
29+ return this .interactions ;
30+ }
31+
32+ @ Override
33+ public InteractionAction add () {
34+ this .interactions = new CopyOnWriteArrayList <Interaction >(new ArrayList <Interaction >());
35+ return this ;
36+ }
37+
38+ @ Override
39+ public InteractionAction welcome (Interaction welcomeInteraction ) {
40+ welcomeInteraction .setType (InteractionType .welcome );
41+ this .interactions .add (welcomeInteraction );
42+ return this ;
43+ }
44+
45+ @ Override
46+ public InteractionAction fallback (Interaction fallbackInteraction ) {
47+ fallbackInteraction .setType (InteractionType .fallback );
48+ this .interactions .add (fallbackInteraction );
49+ return this ;
50+ }
51+
52+ @ Override
53+ public InteractionAction interaction (Interaction userInteraction ) {
54+ userInteraction .setType (InteractionType .user );
55+ this .interactions .add (userInteraction );
56+ return this ;
57+ }
58+
59+ @ Override
60+ public Bot build () {
61+ Objects .requireNonNull (this .interactions , "Please necessary add interactions" );
62+ this .interactions .stream ()
63+ .forEach (interaction -> {
64+
65+ log .info ("Creating Entities..." );
66+ if (interaction .getEntities () != null && interaction .getEntities ().size () > 0 ){
67+ interaction .getEntities ().forEach (entity -> {
68+ Engine .createEntity (entity , this .token );
69+ });
70+ }
71+ //CREATE INTERACTION
72+ log .info ("Creating Interaction -> {}" , interaction );
73+ Engine .creatInteraction (this .bot .getStory (), interaction , this .token );
74+ });
75+
76+ return this .bot ;
77+ }
78+
79+ @ Override
80+ public String getActionName () {
81+ return ACTION_NAME ;
82+ }
83+
84+ @ Override
85+ public int getOrderExecution () {
86+ return 0 ;
87+ }
88+
89+ public Token getToken () {
90+ return token ;
91+ }
92+
9993}
0 commit comments