Subversion Repositories SmartDukaan

Rev

Rev 33968 | Rev 34520 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 33968 Rev 34204
Line 97... Line 97...
97
        }
97
        }
98
 
98
 
99
        if (sendNotificationModel.getStateIds() != null && sendNotificationModel.getStateIds().size() > 0) {
99
        if (sendNotificationModel.getStateIds() != null && sendNotificationModel.getStateIds().size() > 0) {
100
            List<Integer> fofoIds = fofoStoreRepository.selectByWarehouseIds(sendNotificationModel.getStateIds()).stream()
100
            List<Integer> fofoIds = fofoStoreRepository.selectByWarehouseIds(sendNotificationModel.getStateIds()).stream()
101
                    .map(x -> x.getId()).collect(Collectors.toList());
101
                    .map(x -> x.getId()).collect(Collectors.toList());
102
            if(fofoIds.size() > 0) {
102
            if (fofoIds.size() > 0) {
103
                userIds.addAll(userAccountRepository.selectUserIdsByRetailerIds(fofoIds));
103
                userIds.addAll(userAccountRepository.selectUserIdsByRetailerIds(fofoIds));
104
            }
104
            }
105
 
105
 
106
        }
106
        }
107
 
107
 
108
        if(userIds.size() > 0) {
108
        if (userIds.size() > 0) {
109
            for (Integer userId : userIds) {
109
            for (Integer userId : userIds) {
110
                UserCampaign uc = new UserCampaign();
110
                UserCampaign uc = new UserCampaign();
111
                uc.setCampaignId(nc.getId());
111
                uc.setCampaignId(nc.getId());
112
                uc.setUserId(userId);
112
                uc.setUserId(userId);
113
                uc.setPushTimestamp(LocalDateTime.now());
113
                uc.setPushTimestamp(LocalDateTime.now());
Line 186... Line 186...
186
        sendNotificationModel.setUrl(url);
186
        sendNotificationModel.setUrl(url);
187
        this.sendNotification(sendNotificationModel);
187
        this.sendNotification(sendNotificationModel);
188
    }
188
    }
189
 
189
 
190
    @Override
190
    @Override
191
    public void sendWhatsappMessage(String message, String title, String mobile)
191
    public boolean sendWhatsappMessage(String message, String title, String mobile)
192
            throws Exception {
192
            throws Exception {
-
 
193
        boolean isSend=false;
193
        if (isProd) {
194
        if (isProd) {
194
            this.sendWhatsappMessage(WhatsappMessageType.TEXT, message, title, mobile, null, null);
195
            isSend=this.sendWhatsappMessage(WhatsappMessageType.TEXT, message, title, mobile, null, null);
195
        }
196
        }
-
 
197
        return isSend;
196
    }
198
    }
197
 
199
 
198
    @Override
200
    @Override
199
    public void sendWhatsappMediaMessage(String message, String mobile, String mediaUrl, String fileName, WhatsappMessageType whatsappMessageType)
201
    public boolean sendWhatsappMediaMessage(String message, String mobile, String mediaUrl, String fileName, WhatsappMessageType whatsappMessageType)
200
            throws Exception {
202
            throws Exception {
-
 
203
        boolean isSend=false;
201
        if (isProd) {
204
        if (isProd) {
202
            this.sendWhatsappMessage(whatsappMessageType, message, null, mobile, mediaUrl, fileName);
205
            isSend=this.sendWhatsappMessage(whatsappMessageType, message, null, mobile, mediaUrl, fileName);
203
        }
206
        }
204
 
-
 
-
 
207
        return isSend;
205
    }
208
    }
206
 
209
 
207
    @Override
210
    @Override
208
    public void optIn(String phoneNumber) throws Exception {
211
    public void optIn(String phoneNumber) throws Exception {
209
        Map<String, String> requestheaders = new HashMap<>();
212
        Map<String, String> requestheaders = new HashMap<>();
Line 221... Line 224...
221
        requestParams.put("channel", "WHATSAPP");
224
        requestParams.put("channel", "WHATSAPP");
222
        String response = restClient.get("https://media.smsgupshup.com/GatewayAPI/rest", requestParams, requestheaders);
225
        String response = restClient.get("https://media.smsgupshup.com/GatewayAPI/rest", requestParams, requestheaders);
223
        LOGGER.info("response" + response);
226
        LOGGER.info("response" + response);
224
    }
227
    }
225
 
228
 
226
    private void sendWhatsappMessage(WhatsappMessageType whatsappMessageType, String message, String title, String mobile, String mediaUrl, String fileName)
229
    private boolean sendWhatsappMessage(WhatsappMessageType whatsappMessageType, String message, String title, String mobile, String mediaUrl, String fileName)
227
            throws Exception {
230
            throws Exception {
228
        String sendTo = null;
231
        String sendTo = null;
-
 
232
        boolean isSend=false;
229
        if (mobile.length() != 10) {
233
        if (mobile.length() != 10) {
230
            return;
234
            return isSend;
231
        } else {
235
        } else {
232
            sendTo = 91 + mobile;
236
            sendTo = 91 + mobile;
233
        }
237
        }
234
        Map<String, String> requestheaders = new HashMap<>();
238
        Map<String, String> requestheaders = new HashMap<>();
235
        requestheaders.put("Content-Type", "application/x-www-form-urlencoded");
239
        requestheaders.put("Content-Type", "application/x-www-form-urlencoded");
Line 271... Line 275...
271
        JSONObject jsonObject = new JSONObject(response);
275
        JSONObject jsonObject = new JSONObject(response);
272
 
276
 
273
        JSONObject whatsappResponse = (JSONObject) jsonObject.get("response");
277
        JSONObject whatsappResponse = (JSONObject) jsonObject.get("response");
274
        if (whatsappResponse.getString("status").equals("error")) {
278
        if (whatsappResponse.getString("status").equals("error")) {
275
            LOGGER.error("Invalid Whatsapp message, Reason - {}", whatsappResponse.getString("details"));
279
            LOGGER.error("Invalid Whatsapp message, Reason - {}", whatsappResponse.getString("details"));
276
            return;
280
            return isSend;
-
 
281
        }else{
-
 
282
            isSend=true;
277
        }
283
        }
278
        String externalId = whatsappResponse.getString("id");
284
        String externalId = whatsappResponse.getString("id");
279
        String phone = whatsappResponse.getString("phone");
285
        String phone = whatsappResponse.getString("phone");
280
 
286
 
281
        WhatsappMessage whatsappMessage = new WhatsappMessage();
287
        WhatsappMessage whatsappMessage = new WhatsappMessage();
282
        whatsappMessage.setCreatedTimestamp(LocalDateTime.now());
288
        whatsappMessage.setCreatedTimestamp(LocalDateTime.now());
283
        whatsappMessage.setExternalId(externalId);
289
        whatsappMessage.setExternalId(externalId);
284
        whatsappMessage.setDestAddr(phone);
290
        whatsappMessage.setDestAddr(phone);
285
        whatsappMessageRepository.persist(whatsappMessage);
291
        whatsappMessageRepository.persist(whatsappMessage);
-
 
292
        return isSend;
286
    }
293
    }
287
 
294
 
288
    @Override
295
    @Override
289
    public boolean shouldSendWhatsappMessage(String mobile) {
296
    public boolean shouldSendWhatsappMessage(String mobile) {
290
        String destAddr = "91" + mobile;
297
        String destAddr = "91" + mobile;