Compare commits
10 Commits
703907a850
...
e03d232cd1
| Author | SHA1 | Date | |
|---|---|---|---|
| e03d232cd1 | |||
| 136962aa26 | |||
| 1ae3416517 | |||
| f5dbd70b2f | |||
| 65ada32652 | |||
| 4c5efe87e9 | |||
| f510fc851f | |||
| 11119513c7 | |||
| 8a3193afd5 | |||
| 4e2ea2b3ca |
@@ -24,7 +24,7 @@ class MailController:
|
||||
with ApiClient(self.config) as api:
|
||||
req = request.get_json()
|
||||
content = req["content"]
|
||||
payload = json.dumps({"content": content})
|
||||
payload = json.dumps(content)
|
||||
print(payload)
|
||||
|
||||
api.default_headers["Authorization"] = f"Bearer {self._auth_data.get_token()}"
|
||||
|
||||
@@ -23,11 +23,10 @@ class SmsController:
|
||||
def send_sms(self):
|
||||
try:
|
||||
with ApiClient(self.config) as api:
|
||||
payload = json.dumps({"content": "The game is over ! Go check the board"})
|
||||
api.default_headers["Authorization"] = f"Bearer {self._auth_data.get_token()}"
|
||||
sms_api = SmsApi(api)
|
||||
|
||||
sms_api.example(StrictStr(payload))
|
||||
sms_api.example(StrictStr('{"content": "The game is over ! Go check the board"}'))
|
||||
return jsonify({"success": True, "message": None}), 200
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
@@ -6,7 +6,6 @@ services:
|
||||
container_name: boardmate-api
|
||||
ports:
|
||||
- "8000:8080"
|
||||
- "5005:5005"
|
||||
environment:
|
||||
SSL_KEYSTORE_PATH: "/certs/keystore.p12"
|
||||
BROKER_URL: "tcp://api-broker:1883"
|
||||
@@ -17,7 +16,7 @@ services:
|
||||
BROKER_PASSWORD: "hepl"
|
||||
JWT_SECRET: "enY3OWU4djFyMTByNTZhcG9uY3Z0djQ5cnY0eDhhNWM0bjg5OTRjNDhidA=="
|
||||
WEBEX_BOT_TOKEN: "YmU0NTdkNDMtYTg1ZC00M2YyLTk3YzUtODA1MWFmOTk1NjA1ZmU3MTYxNGUtYWZm_P0A1_14a2639d-5e4d-48b4-9757-f4b8a23372de"
|
||||
WEBEX_CLIENT_TOKEN: "OWMzYWYyYTgtMWMxYS00NjI5LTkwODgtMTVlZGYwMWNiM2MyNWViMzA2YWMtZTg0_P0A1_14a2639d-5e4d-48b4-9757-f4b8a23372de"
|
||||
WEBEX_CLIENT_TOKEN: "YjY2NzRkMTktZTEzMi00YmQyLTk2N2ItZTU4NDhlNjc0MDUyZGJmMDQwOTYtYTkx_P0A1_14a2639d-5e4d-48b4-9757-f4b8a23372de"
|
||||
WEBEX_SHARED_SECRET: "cUxSc0ZjNVBZVG5oRmhqaVN0YUtMTEVZb0pIZW5EY2Rwa0hUaWdiVm9nWlJiY2t5aFdmTjhvWmQ5U3R3TDIxVE1CRTl4VGJldVI3TFdVa3lMbFVPZUVSMkZPSnBHTjk="
|
||||
TWILIO_SERVICE_ID: "MGc971109e0d7e7e17ba93ae3b641d8673"
|
||||
TWILIO_ACCOUNT_SID: "ACf041152850f4535c266bb82644bda152"
|
||||
|
||||
@@ -2,6 +2,8 @@ package be.naaturel.boardmateapi.controllers;
|
||||
|
||||
import be.naaturel.boardmateapi.common.helpers.Logger;
|
||||
import be.naaturel.boardmateapi.services.SendgridService;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -27,8 +29,9 @@ public class EmailController {
|
||||
@PostMapping("/mail/send")
|
||||
public ResponseEntity<String> send(@RequestBody String payload) {
|
||||
try {
|
||||
Logger.displayInfo(payload);
|
||||
service.send("laurent0206.cr@gmail.com", "Hello from board mate !", payload);
|
||||
|
||||
service.send("laurent0206.cr@gmail.com", "Hello from Board Mate!", payload);
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -14,6 +14,8 @@ import com.sendgrid.helpers.mail.objects.Email;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class SendgridService {
|
||||
|
||||
@@ -28,9 +30,9 @@ public class SendgridService {
|
||||
this.senderEmail = email;
|
||||
}
|
||||
|
||||
public void send(String dst, String subject, String text) throws ServiceException {
|
||||
public void send(String dst, String subject, String payload) throws ServiceException {
|
||||
try {
|
||||
Content content = new Content("text/plain", formatContent(text));
|
||||
Content content = new Content("text/plain",payload);
|
||||
Mail mail = new Mail(this.senderEmail, subject, new Email(dst), content);
|
||||
|
||||
Request request = new Request();
|
||||
@@ -45,28 +47,4 @@ public class SendgridService {
|
||||
throw new ServiceException("Failed to send email : " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private String formatContent(String content) throws JsonProcessingException {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode root = mapper.readTree(content);
|
||||
|
||||
StringBuilder mailBody = new StringBuilder();
|
||||
|
||||
mailBody.append("White: ").append(root.get("white_name").asText()).append("\n");
|
||||
mailBody.append("Black: ").append(root.get("black_name").asText()).append("\n");
|
||||
mailBody.append("Time Control: ")
|
||||
.append(root.get("time_control").asInt())
|
||||
.append(" + ")
|
||||
.append(root.get("increment").asInt())
|
||||
.append("\n");
|
||||
mailBody.append("Timestamp: ").append(root.get("timestamp").asLong()).append("\n\n");
|
||||
|
||||
mailBody.append("Moves:\n");
|
||||
int i = 1;
|
||||
for (JsonNode move : root.get("moves")) {
|
||||
mailBody.append(i++).append(". ").append(move.asText()).append("\n");
|
||||
}
|
||||
|
||||
return mailBody.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,10 +22,7 @@ public class TwilioService {
|
||||
|
||||
public void send(String msg) throws ServiceException {
|
||||
try {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode jsonNode = mapper.readTree(msg);
|
||||
String content = jsonNode.get("content").asText();
|
||||
Message.creator(new PhoneNumber("+32496533833"), this.serviceId, content).create();
|
||||
Message.creator(new PhoneNumber("+32496533833"), this.serviceId, msg).create();
|
||||
} catch (Exception e){
|
||||
throw new ServiceException("Failed to send message :" + e.getMessage());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user