Skip to content

Commit 942c3a7

Browse files
committed
update client, add error catcher, fix full example
1 parent 06d714b commit 942c3a7

18 files changed

+138
-146
lines changed

pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111
<groupId>com.green-api</groupId>
1212
<artifactId>whatsapp-chatbot-java</artifactId>
13-
<version>0.0.2</version>
13+
<version>0.0.3</version>
1414
<name>whatsapp-chatbot-java</name>
1515
<description>whatsapp-chatbot-java</description>
1616
<licenses>
@@ -34,7 +34,7 @@
3434
</developers>
3535
<properties>
3636
<java.version>17</java.version>
37-
<whatsapp-api-client-java.version>0.1.3</whatsapp-api-client-java.version>
37+
<whatsapp-api-client-java.version>0.1.4</whatsapp-api-client-java.version>
3838
<snakeyaml.version>2.2</snakeyaml.version>
3939
</properties>
4040
<distributionManagement>

src/main/java/com/greenapi/chatbot/docs/README_RU.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ implementation group: 'com.green-api', name: 'whatsapp-chatbot-java', version: '
4141
Для этого вам понадобится создать свой класс конфигурации и добавить в него следующие бины:
4242

4343
```java
44+
4445
@Configuration
4546
public class BotDefaultConfigExample {
4647

@@ -109,6 +110,7 @@ green-api:
109110
С помощью данного класса и метода `createBot()` вы можете инициализировать объект бота:
110111

111112
```java
113+
112114
@SpringBootApplication
113115
public class BotStarterClassExample {
114116
@@ -190,6 +192,7 @@ public class BaseStartScene extends Scene {
190192
В этом примере бот имеет только одну сцену и ответит только на сообщение `message`.
191193

192194
```java
195+
193196
@SpringBootApplication
194197
public class BotStarterClassExample {
195198
@@ -220,6 +223,7 @@ public class BotStarterClassExample {
220223
Ссылка на пример: [EventStartScene.java](../examples/event/EventStartScene.java).
221224

222225
```java
226+
223227
@Log4j2
224228
public class EventStartScene extends Scene {
225229
@@ -230,13 +234,13 @@ public class EventStartScene extends Scene {
230234
231235
return currentState;
232236
}
233-
237+
234238
// Для обработки исходящих сообщений
235239
@Override
236240
public State processOutgoingMessage(MessageWebhook outgoingMessage, State currentState) {
237241
return super.processOutgoingMessage(outgoingMessage, currentState);
238242
}
239-
243+
240244
// Для обработки статусов исходящих сообщений
241245
@Override
242246
public State processOutgoingMessageStatus(OutgoingMessageStatus outgoingMessageStatus, State currentState) {

src/main/java/com/greenapi/chatbot/examples/base/BaseStartScene.java

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.greenapi.chatbot.examples.base;
22

33
import com.greenapi.chatbot.pkg.Scene;
4-
import com.greenapi.chatbot.pkg.state.MapState;
54
import com.greenapi.chatbot.pkg.state.State;
65
import com.greenapi.client.pkg.models.notifications.MessageWebhook;
76

src/main/java/com/greenapi/chatbot/examples/echo/EchoStartScene.java

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.greenapi.chatbot.examples.echo;
22

33
import com.greenapi.chatbot.pkg.Scene;
4-
import com.greenapi.chatbot.pkg.state.MapState;
54
import com.greenapi.chatbot.pkg.state.State;
65
import com.greenapi.client.pkg.models.notifications.MessageWebhook;
76

src/main/java/com/greenapi/chatbot/examples/event/EventStartScene.java

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.greenapi.chatbot.examples.event;
22

33
import com.greenapi.chatbot.pkg.Scene;
4-
import com.greenapi.chatbot.pkg.state.MapState;
54
import com.greenapi.chatbot.pkg.state.State;
65
import com.greenapi.client.pkg.models.notifications.IncomingBlock;
76
import com.greenapi.client.pkg.models.notifications.IncomingCall;

src/main/java/com/greenapi/chatbot/examples/filters/FiltersStartScene.java

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.greenapi.chatbot.pkg.Scene;
44
import com.greenapi.chatbot.pkg.filters.Filter;
5-
import com.greenapi.chatbot.pkg.state.MapState;
65
import com.greenapi.chatbot.pkg.state.State;
76
import com.greenapi.client.pkg.models.notifications.MessageWebhook;
87

Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.greenapi.chatbot.examples.full;
22

33
import com.greenapi.chatbot.pkg.Scene;
4-
import com.greenapi.chatbot.pkg.filters.Filter;
5-
import com.greenapi.chatbot.pkg.state.MapState;
64
import com.greenapi.chatbot.pkg.state.State;
75
import com.greenapi.client.pkg.models.Contact;
86
import com.greenapi.client.pkg.models.Option;
@@ -14,54 +12,53 @@ public class ChooseScene extends Scene {
1412

1513
@Override
1614
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!");
3718
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);
6119
}
6220

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+
}
6663
}
6764
}

src/main/java/com/greenapi/chatbot/examples/full/FullStartScene.java

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.greenapi.chatbot.examples.full;
22

33
import com.greenapi.chatbot.pkg.Scene;
4-
import com.greenapi.chatbot.pkg.state.MapState;
54
import com.greenapi.chatbot.pkg.state.State;
65
import com.greenapi.client.pkg.models.notifications.MessageWebhook;
76

src/main/java/com/greenapi/chatbot/examples/full/InputLinkScene.java

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.greenapi.chatbot.examples.full;
22

33
import com.greenapi.chatbot.pkg.Scene;
4-
import com.greenapi.chatbot.pkg.state.MapState;
54
import com.greenapi.chatbot.pkg.state.State;
65
import com.greenapi.client.pkg.models.notifications.MessageWebhook;
76

src/main/java/com/greenapi/chatbot/examples/media/MediaStartScene.java

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.greenapi.chatbot.examples.media;
22

33
import com.greenapi.chatbot.pkg.Scene;
4-
import com.greenapi.chatbot.pkg.state.MapState;
54
import com.greenapi.chatbot.pkg.state.State;
65
import com.greenapi.client.pkg.models.notifications.ContactMessageWebhook;
76
import com.greenapi.client.pkg.models.notifications.FileMessageWebhook;

src/main/java/com/greenapi/chatbot/examples/state/InputPasswordScene.java

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.greenapi.chatbot.examples.state;
22

33
import com.greenapi.chatbot.pkg.Scene;
4-
import com.greenapi.chatbot.pkg.state.MapState;
54
import com.greenapi.chatbot.pkg.state.State;
65
import com.greenapi.client.pkg.models.notifications.MessageWebhook;
76

src/main/java/com/greenapi/chatbot/examples/state/InputUsernameScene.java

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.greenapi.chatbot.examples.state;
22

33
import com.greenapi.chatbot.pkg.Scene;
4-
import com.greenapi.chatbot.pkg.state.MapState;
54
import com.greenapi.chatbot.pkg.state.State;
65
import com.greenapi.client.pkg.models.notifications.MessageWebhook;
76

src/main/java/com/greenapi/chatbot/examples/state/StateStartScene.java

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.greenapi.chatbot.examples.state;
22

33
import com.greenapi.chatbot.pkg.Scene;
4-
import com.greenapi.chatbot.pkg.state.MapState;
54
import com.greenapi.chatbot.pkg.state.State;
65
import com.greenapi.client.pkg.models.notifications.MessageWebhook;
76

src/main/java/com/greenapi/chatbot/pkg/Bot.java

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.greenapi.client.pkg.api.GreenApi;
55
import com.greenapi.client.pkg.api.webhook.NotificationMapper;
66
import com.greenapi.client.pkg.api.webhook.WebhookConsumer;
7-
import com.greenapi.client.pkg.models.response.Settings;
87
import lombok.AccessLevel;
98
import lombok.AllArgsConstructor;
109
import lombok.Builder;

0 commit comments

Comments
 (0)