-
Notifications
You must be signed in to change notification settings - Fork 0
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
Saving sms conversations in CrmActivity #98
Conversation
2dc2edf
to
11fa2b6
Compare
@@ -255,6 +296,9 @@ public EnvironmentConfig.CRMFieldDefinitions getFieldDefinitions() { | |||
} | |||
|
|||
protected void setTaskFields(SObject task, CrmTask crmTask) { | |||
if (crmTask != null) { |
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.
@VSydor Would this ever be null? And if so, there are uses of crmTask
below that fall outside of this check.
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.
Should have been crmTask.id check. Will update this line.
src/main/java/com/impactupgrade/nucleus/service/segment/SfdcCrmService.java
Outdated
Show resolved
Hide resolved
@Path("/webhook/message/onMessageAdded") // TODO: replace with the correct url | ||
@POST | ||
@Consumes(MediaType.APPLICATION_FORM_URLENCODED) | ||
@Produces(MediaType.APPLICATION_XML) //TODO: define what type to return |
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.
Twilio webhooks expect APPLICATION_JSON I believe, although this method should simply return a 200 response.
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.
Will update to json and ok empty response
src/main/java/com/impactupgrade/nucleus/controller/TwilioController.java
Outdated
Show resolved
Hide resolved
addMessage(crmTask, messageSid); | ||
upsertCrmTask(env, crmTask); | ||
|
||
return Response.ok().build(); // TODO: what to return? |
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.
This is fine as-is
src/main/java/com/impactupgrade/nucleus/controller/TwilioController.java
Show resolved
Hide resolved
ddddff8
to
58ec129
Compare
@@ -206,6 +206,7 @@ public static class Salesforce extends Platform { | |||
public SalesforceCustomFields customQueryFields = new SalesforceCustomFields(); | |||
|
|||
public String defaultCampaignId = ""; | |||
public String defaultTaskAssignee = ""; |
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.
No longer needed and we're unlikely to need this in practice -- remove?
@@ -258,11 +308,22 @@ public EnvironmentConfig.CRMFieldDefinitions getFieldDefinitions() { | |||
} | |||
|
|||
protected void setTaskFields(SObject task, CrmTask crmTask) { | |||
if (crmTask.id != null) { | |||
task.setField("Id", crmTask.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.
Don't set the ID in this method. Instead, have updateTask
set it prior to calling setTaskFields
. It's a precedent we've set in these services in general, separating the core logic from the specific fields.
29c5e8f
to
4742f1f
Compare
e7fbd7e
to
1d17e0e
Compare
@@ -221,6 +221,8 @@ default void batchFlush() throws Exception { | |||
// MISC | |||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
String insertTask(CrmTask crmTask) throws Exception; | |||
String updateTask(CrmTask crmTask) throws Exception; | |||
Optional<CrmTask> getTaskBySubject(String subject) throws Exception; |
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.
@VSydor Picky, but precedent setting:
Could we name this something like getTaskByExtRef ("external reference")? It's essentially a way to look up a subject based on an external notion, like a Twilio Conversation 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.
Sure - will rename the method
@@ -774,6 +774,13 @@ public Optional<SObject> getUserByEmail(String email, String... extraFields) thr | |||
return querySingle(query); | |||
} | |||
|
|||
protected static final String TASK_FIELDS = "Id, WhoId, OwnerId, Subject, description, status, priority, activityDate"; | |||
|
|||
public Optional<SObject> getTaskBySubject(String subject) throws ConnectionException, InterruptedException { |
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.
In EnvironmentConfig, could we instead define a new fieldname that must be set, allowing activities to have a external reference ID (ex: Twilio Conference ID) set as a custom field? Similar to what we do with Stripe charges and the paymentGatewayTransactionId field name definition.
Just concerned about tying this to Subject
long-term.
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.
Will do
@Context HttpServletRequest request | ||
) throws Exception { | ||
Environment env = envFactory.init(request); | ||
SecurityUtil.verifyApiKey(env); //TODO: not needed? |
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.
Correct, kill this line. No auth for inbound, write-only webhook APIs.
SMS, | ||
inboundMessageWebhookData.message, | ||
inboundMessageWebhookData.externalReferenceId, | ||
null); // TODO: use customParams to contain conversation 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.
Clarify this one for me?
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.
In MBT webhook we don't have conversation id (as we have in Twilio webhook)
So need to get it from somewhere (mb it's possible to configure custom params on MBT side?)
@Context HttpServletRequest request | ||
) throws Exception { | ||
Environment env = envFactory.init(request); | ||
SecurityUtil.verifyApiKey(env); //TODO: not needed? |
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.
Ditto
Environment env = envFactory.init(request); | ||
//SecurityUtil.verifyApiKey(env); //TODO: not needed? | ||
|
||
log.info("Mailchimp message event batch received. Batch size: {}.", webhookPayload.events.size()); |
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.
Oy! This is actually pretty refreshing! Cool to see they're batching them...
|
||
@Path("/mailchimp") | ||
public class MailchimpController { | ||
|
||
private static final Logger log = LogManager.getLogger(MailchimpController.class); | ||
|
||
private static final Set<String> SUPPORTED_EVENT_TYPES = Set.of( //TODO: move to env config? |
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.
Eh, maybe at some point, but the types are strongly tied to chunks of code, so making this config-driven would be tough. Same issue in StripeController
if (event == null) { | ||
return; | ||
} | ||
if (!SUPPORTED_EVENT_TYPES.contains(event.eventType)) { |
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.
Is the array of types and this if
block really necessary? Since you're explicitly looking for "send" and then doing a "skipping event type..." log for everything else, this whole block technically isn't needed? Same pattern as StripeController
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.
Will follow the pattern from Stripe controller
EMAIL, | ||
event.message.subject, | ||
event.message.id, | ||
event.message.email); |
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.
Just to confirm, this will store the actual email body, right? Desirable as a paper trail...
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.
"event.message.email" is used here as a conversation id key (same way as explicit conversation sid in Twilio Controller) to have all the messages sent to the same email address in 1 CrmActivity. Can be too much for 1 activity so we can introduce some additional value (like date for example to contain messages for specific time window)
event.message.email = email address of the recipient
@@ -16,16 +18,25 @@ public CrmTask() { | |||
} | |||
|
|||
public CrmTask(String targetId, String assignTo, String subject, String description, |
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.
Picky, and I'm sorry if we went back and forth on this:
Should we call this something like CrmActivity
? Logically, these are all activities. Only in SFDC land are they modeled as "tasks" (which I still think was a weird design choice on their part)
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.
Sure - will rename to CrmActivity.
11dc384
to
8c31782
Compare
d4cc3cc
to
7331b7e
Compare
61bd24c
to
b1005af
Compare
…roller for manual testing Twilio Conversation webhook added (onMessageAdded) Code review comments pulled logic into MessagingService, convering the controller endpoint into a generic conversations webhook Removed unsuned task config property; Setting task id in update method Added MBT inbound/message-status webhooks; Saving inbound messages into crm activity (tasks) Added basic processing of Mailchimp message webhooks Code review comments Using combinations of webhook data fields as a converstion key for MBT and Mailchimp minor fixes moved the logic to a new ActivityService
b1005af
to
a9127ce
Compare
No description provided.