-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#3535] Send messages to Whatsapp Cloud #3615
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,7 @@ public List<KeyValue<String, SpecificRecordBase>> sendMessage(SendMessageRequest | |
results.add(KeyValue.pair(getId(errorPayload).toString(), errorPayload)); | ||
} | ||
updateDeliveryState(message, DeliveryState.FAILED); | ||
results.add(KeyValue.pair(message.getId(), message)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fixes a sofar unknown bug |
||
return results; | ||
} catch (Exception e) { | ||
log.error(String.format("Failed to send a \n SendMessageRequest: %s", sendMessageRequest), e); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package co.airy.core.sources.whatsapp.api; | ||
|
||
import co.airy.avro.communication.Message; | ||
import co.airy.core.sources.whatsapp.dto.Conversation; | ||
import co.airy.core.sources.whatsapp.dto.SendMessageRequest; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.stereotype.Service; | ||
|
||
|
||
@Service | ||
public class Mapper { | ||
private final ObjectMapper objectMapper; | ||
|
||
public Mapper(@Qualifier("metaObjectMapper") ObjectMapper objectMapper) { | ||
this.objectMapper = objectMapper; | ||
} | ||
|
||
public JsonNode fromSendMessageRequest(SendMessageRequest sendMessageRequest) throws JsonProcessingException { | ||
final Message message = sendMessageRequest.getMessage(); | ||
final Conversation conversation = sendMessageRequest.getConversation(); | ||
final ObjectNode payload = ((ObjectNode) objectMapper.readTree(message.getContent())); | ||
payload.put("messaging_product", "whatsapp"); | ||
payload.put("recipient_type", "individual"); | ||
payload.put("to", conversation.getSourceConversationId()); | ||
return payload; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package co.airy.core.sources.whatsapp.api; | ||
|
||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class MetaConfig { | ||
@Bean | ||
@Qualifier("metaObjectMapper") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So far the meta-object mapper has been the same as ours in terms of config. It's better however to explicitly split them. |
||
public ObjectMapper metaObjectMapper() { | ||
return new ObjectMapper() | ||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) | ||
.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package co.airy.core.sources.whatsapp.api.model; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class SendMessageResponse { | ||
private String messagingProduct; | ||
private List<Contact> contacts; | ||
private List<Message> messages; | ||
|
||
public String getMessageId() { | ||
if (messages != null && messages.size() > 0) { | ||
return messages.get(0).getId(); | ||
} | ||
return null; | ||
} | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class Contact { | ||
private String input; | ||
private String waId; | ||
} | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class Message { | ||
private String id; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also refactored this deprecated import