|
6 | 6 | import one.mixin.bot.HttpClient; |
7 | 7 | import one.mixin.bot.SessionToken; |
8 | 8 | import one.mixin.bot.api.MixinResponse; |
| 9 | +import one.mixin.bot.util.ConversationUtil; |
9 | 10 | import one.mixin.bot.vo.*; |
10 | 11 |
|
11 | 12 | import java.io.IOException; |
12 | 13 | import java.security.KeyPair; |
13 | | -import java.util.List; |
14 | | -import java.util.Objects; |
15 | | -import java.util.Random; |
16 | | -import java.util.UUID; |
| 14 | +import java.util.*; |
17 | 15 |
|
18 | 16 | import static jvmMain.java.Config.*; |
19 | 17 | import static one.mixin.bot.SessionKt.encryptPin; |
20 | | -import static one.mixin.bot.extension.Base64ExtensionKt.base64Decode; |
21 | 18 | import static one.mixin.bot.extension.Base64ExtensionKt.base64Encode; |
| 19 | +import static one.mixin.bot.util.Base64UtilKt.base64Decode; |
22 | 20 | import static one.mixin.bot.util.CryptoUtilKt.*; |
23 | 21 |
|
24 | 22 | public class Sample { |
@@ -72,7 +70,12 @@ public static void main(String[] args) { |
72 | 70 | withdrawalToAddress(client, addressId, userAesKey); |
73 | 71 |
|
74 | 72 | // Delete address |
75 | | - deleteAddress(client, addressId,userAesKey); |
| 73 | + deleteAddress(client, addressId, userAesKey); |
| 74 | + |
| 75 | + //Use bot's token |
| 76 | + client.setUserToken(null); |
| 77 | + // Send text message |
| 78 | + sendTextMessage(client, "639ec50a-d4f1-4135-8624-3c71189dcdcc", "Test message"); |
76 | 79 | } catch (InterruptedException | IOException e) { |
77 | 80 | System.out.println(e.getMessage()); |
78 | 81 | } |
@@ -205,6 +208,21 @@ private static void getFee(HttpClient client) throws IOException { |
205 | 208 | } |
206 | 209 | } |
207 | 210 |
|
| 211 | + private static void sendTextMessage(HttpClient client, String recipientId, String text) throws IOException { |
| 212 | + List<MessageRequest> messageRequests = new ArrayList<>(); |
| 213 | + messageRequests.add(new MessageRequest( |
| 214 | + ConversationUtil.Companion.generateConversationId(userId, recipientId), |
| 215 | + recipientId, UUID.randomUUID().toString(), "PLAIN_TEXT", |
| 216 | + Base64.getEncoder().encodeToString(text.getBytes()), null, null |
| 217 | + )); |
| 218 | + MixinResponse messageResponse = client.getMessageService().postMessageCall(messageRequests).execute().body(); |
| 219 | + if (messageResponse.isSuccess()) { |
| 220 | + System.out.println("Send success"); |
| 221 | + } else { |
| 222 | + System.out.println("Send fail"); |
| 223 | + } |
| 224 | + } |
| 225 | + |
208 | 226 | private static SessionToken getUserToken(User user, KeyPair sessionKey, boolean isRsa) { |
209 | 227 | if (isRsa) { |
210 | 228 | return new SessionToken.RSA(user.getUserId(), user.getSessionId(), sessionKey.getPrivate()); |
|
0 commit comments