diff --git a/api/tasks/createChat.cfm b/api/tasks/createChat.cfm index 9bf7020..445766b 100644 --- a/api/tasks/createChat.cfm +++ b/api/tasks/createChat.cfm @@ -35,11 +35,18 @@ try { apiAbort({ "OK": false, "ERROR": "missing_params", "MESSAGE": "BusinessID is required" }); } + // Look up "Chat With Staff" task type for this business + ttQuery = queryTimed(" + SELECT ID FROM tt_TaskTypes + WHERE BusinessID = :businessID AND Name LIKE '%Chat%' + LIMIT 1 + ", { businessID: { value: businessID, cfsqltype: "cf_sql_integer" } }, { datasource: "payfrit" }); + chatTaskTypeID = ttQuery.recordCount > 0 ? ttQuery.ID : 0; + // ServicePointID = 0 is allowed for remote chats (non-dine-in users) // In that case, we use userID to match existing chats // Check for existing open chat at this service point - // An open chat is one where TaskTypeID=2 (Chat) and CompletedOn IS NULL forceNew = structKeyExists(data, "ForceNew") && data.ForceNew == true; if (!forceNew) { @@ -51,7 +58,7 @@ try { FROM Tasks t LEFT JOIN ChatMessages cm2 ON cm2.TaskID = t.ID AND cm2.SenderUserID = :userID WHERE t.BusinessID = :businessID - AND t.TaskTypeID = 2 + AND (t.TaskTypeID = :chatTypeID OR t.Title LIKE 'Chat%') AND t.CompletedOn IS NULL AND ( (t.OrderID = :orderID AND :orderID > 0) @@ -63,6 +70,7 @@ try { LIMIT 1 ", { businessID: { value: businessID, cfsqltype: "cf_sql_integer" }, + chatTypeID: { value: chatTaskTypeID, cfsqltype: "cf_sql_integer" }, servicePointID: { value: servicePointID, cfsqltype: "cf_sql_integer" }, orderID: { value: orderID, cfsqltype: "cf_sql_integer" }, userID: { value: userID, cfsqltype: "cf_sql_integer" } @@ -164,7 +172,7 @@ try { sourceID = userID; } - // Insert task with TaskTypeID = 2 (Chat) + // Insert task with business-specific Chat task type queryTimed(" INSERT INTO Tasks ( BusinessID, @@ -181,7 +189,7 @@ try { :businessID, :categoryID, :orderID, - 2, + :taskTypeID, :title, :details, 0, @@ -193,6 +201,7 @@ try { businessID: { value: businessID, cfsqltype: "cf_sql_integer" }, categoryID: { value: categoryID, cfsqltype: "cf_sql_integer" }, orderID: { value: orderID > 0 ? orderID : javaCast("null", ""), cfsqltype: "cf_sql_integer", null: orderID == 0 }, + taskTypeID: { value: chatTaskTypeID, cfsqltype: "cf_sql_integer", null: chatTaskTypeID == 0 }, title: { value: taskTitle, cfsqltype: "cf_sql_varchar" }, details: { value: taskDetails, cfsqltype: "cf_sql_varchar" }, sourceType: { value: sourceType, cfsqltype: "cf_sql_varchar" }, diff --git a/api/tasks/listPending.cfm b/api/tasks/listPending.cfm index d5d9f70..4a8abe4 100644 --- a/api/tasks/listPending.cfm +++ b/api/tasks/listPending.cfm @@ -42,8 +42,8 @@ - - + +