1
1
package com .greenapi .chatbot .examples .full ;
2
2
3
3
import com .greenapi .chatbot .pkg .Scene ;
4
- import com .greenapi .chatbot .pkg .filters .Filter ;
5
- import com .greenapi .chatbot .pkg .state .MapState ;
6
4
import com .greenapi .chatbot .pkg .state .State ;
7
5
import com .greenapi .client .pkg .models .Contact ;
8
6
import com .greenapi .client .pkg .models .Option ;
@@ -14,54 +12,53 @@ public class ChooseScene extends Scene {
14
12
15
13
@ Override
16
14
public State processIncomingMessage (MessageWebhook incomingMessage , State currentState ) {
17
-
18
- if (Filter .isMessageTextExpected (incomingMessage , "1" )) {
19
- answerWithText (incomingMessage , "Hi! This is answerWithText!" );
20
-
21
- return currentState ;
22
-
23
- } else if (Filter .isMessageTextExpected (incomingMessage , "2" )) {
24
- answerWithText (incomingMessage , "Send me the link on File:" );
25
-
26
- return activateNextScene (currentState , new InputLinkScene ());
27
-
28
- } else if (Filter .isMessageTextExpected (incomingMessage , "3" )) {
29
- var options = new ArrayList <Option >();
30
- options .add (new Option ("Red" ));
31
- options .add (new Option ("Blue" ));
32
- options .add (new Option ("Green" ));
33
- options .add (new Option ("Pink" ));
34
-
35
- answerWithPoll (incomingMessage , "choose color" , options , false );
36
-
15
+ var text = getText (incomingMessage );
16
+ if (text == null ) {
17
+ answerWithText (incomingMessage , "PLease send a text message!" );
37
18
return currentState ;
38
-
39
- } else if (Filter .isMessageTextExpected (incomingMessage , "4" )) {
40
- answerWithLocation (incomingMessage , "Home" , "Cdad. de La Paz 2969, Buenos Aires" , -34.5553558 , -58.4642510 );
41
-
42
- return currentState ;
43
-
44
- } else if (Filter .isMessageTextExpected (incomingMessage , "5" )) {
45
- var contact = Contact .builder ()
46
- .firstName ("first" )
47
- .lastName ("last" )
48
- .middleName ("middle" )
49
- .company ("Green API" )
50
- .phoneContact (11111111111L )
51
- .build ();
52
-
53
- answerWithContact (incomingMessage , contact );
54
-
55
- return currentState ;
56
-
57
- } else if (Filter .isMessageTextExpected (incomingMessage , "6" )) {
58
- answerWithText (incomingMessage , "Goodbye!" );
59
-
60
- return activateStartScene (currentState );
61
19
}
62
20
63
- answerWithText (incomingMessage , "Please send numbers - 1, 2, 3, 4, 5 or 6" );
64
-
65
- return currentState ;
21
+ switch (text ) {
22
+ case "1" -> {
23
+ answerWithText (incomingMessage , "Hi! This is answerWithText!" );
24
+ return currentState ;
25
+ }
26
+ case "2" -> {
27
+ answerWithText (incomingMessage , "Send me the link on File:" );
28
+ return activateNextScene (currentState , new InputLinkScene ());
29
+ }
30
+ case "3" -> {
31
+ var options = new ArrayList <Option >();
32
+ options .add (new Option ("Red" ));
33
+ options .add (new Option ("Blue" ));
34
+ options .add (new Option ("Green" ));
35
+ options .add (new Option ("Pink" ));
36
+ answerWithPoll (incomingMessage , "choose color" , options , false );
37
+ return currentState ;
38
+ }
39
+ case "4" -> {
40
+ answerWithLocation (incomingMessage , "Home" , "Cdad. de La Paz 2969, Buenos Aires" , -34.5553558 , -58.4642510 );
41
+ return currentState ;
42
+ }
43
+ case "5" -> {
44
+ var contact = Contact .builder ()
45
+ .firstName ("first" )
46
+ .lastName ("last" )
47
+ .middleName ("middle" )
48
+ .company ("Green API" )
49
+ .phoneContact (11111111111L )
50
+ .build ();
51
+ answerWithContact (incomingMessage , contact );
52
+ return currentState ;
53
+ }
54
+ case "6" -> {
55
+ answerWithText (incomingMessage , "Goodbye!" );
56
+ return activateStartScene (currentState );
57
+ }
58
+ default -> {
59
+ answerWithText (incomingMessage , "Please send numbers - 1, 2, 3, 4, 5 or 6" );
60
+ return currentState ;
61
+ }
62
+ }
66
63
}
67
64
}
0 commit comments