Comments (11)
Hi @CharlesMangwa,
I've found the bug and how to fix it, though I need to ask for confirmation from @reichert621 regarding the fix.
From line 131 - 142, it fetches metadata
from the PUT
request, merges it with extra fields and then transform some of fields after sanitizing it.
papercups/lib/chat_api_web/controllers/customer_controller.ex
Lines 127 to 144 in 7c850c4
Based from the line map transformation the given map below (came from PUT request):
{
"metadata": {
"social handle": "mikoto"
}
}
will become
%{
"ip" => nil,
"last_seen_at" => ~U[2021-12-04 11:11:38.308617Z],
"social handle" => "mikoto"
}
and since updating a metadata calls Customers.update_customer_metadata
function, the Customer.metadata_changeset
will also be called, processing the merged map. Now, since metadata
key is no longer present upon calling the changeset it becomes null
papercups/lib/chat_api/customers/customer.ex
Lines 121 to 142 in 7c850c4
Fix
The fix is actually simple, instead of
papercups/lib/chat_api/customers.ex
Lines 284 to 290 in 7c850c4
I make it like this
def sanitize_metadata(metadata) do
metadata
|> sanitize_metadata_email()
|> sanitize_metadata_external_id()
|> sanitize_metadata_current_url()
|> sanitize_ad_hoc_metadata()
|> prepare_metadata()
end
def prepare_metadata(metadata) when is_map(metadata), do: %{metadata: metadata}
def prepare_metadata(metadata), do: metadata
After applying the change, here's what Ecto.Changeset prints out.
#Ecto.Changeset<
action: nil,
changes: %{
metadata: %{
"ip" => nil,
"last_seen_at" => ~U[2021-12-04 11:18:05.094519Z],
"social handle" => "mikoto"
}
},
errors: [],
data: #ChatApi.Customers.Customer<>,
v
from papercups.
I believe you should use PUT request on https://app.papercups.io/api/v1/customers/[id]/metadata
as described in the router.ex
file
papercups/lib/chat_api_web/router.ex
Line 52 in 7c850c4
The reason https://app.papercups.io/api/v1/customers/[id]/
returns a null is because the changeset used in update_customer
does not pick up the metadata
key.
papercups/lib/chat_api/customers.ex
Lines 254 to 258 in 7c850c4
papercups/lib/chat_api/customers/customer.ex
Lines 91 to 119 in 7c850c4
But when you look at changeset used in Customers.update_customer_metadata
it picks up the metadata
key.
papercups/lib/chat_api/customers/customer.ex
Lines 121 to 143 in 7c850c4
from papercups.
Thanks for the lead @jeepers3327! I forgot to mention in my initial description that I did try a PUT
on https://app.papercups.io/api/v1/customers/[id]/metadata
but it returns
{
"errors": {
"detail": "Not Found"
}
}
even though the id
I provided does exist and all. Am I missing something obvious?
FWIW: I also tried https://app.papercups.io/api/customers/[id]/metadata
(without the v1
). This one does return the data
object but metadata
is still null
.
from papercups.
Hi @CharlesMangwa,
Could you try accessing this endpoint get("/customers/:id/exists", CustomerController, :exists)
with your id
and tell me the result if it exist or not. Based on https://github.com/papercups-io/papercups/blob/master/lib/chat_api_web/router.ex, it shouldn't matter whether there's a v1
prefix on the api endpoint or not.
Note: I don't really launch the application on my local or the hosted version, I just give out advice based on the code.
from papercups.
hey @jeepers3327, thanks for your help, it's much appreciated!
There seem to be different scopes actually:
papercups/lib/chat_api_web/router.ex
Line 35 in 1ad023a
papercups/lib/chat_api_web/router.ex
Line 182 in 1ad023a
with only the former accepting put("/customers/:id/metadata")
:
papercups/lib/chat_api_web/router.ex
Line 52 in 1ad023a
That could explain why trying to access /api/v1/customers/[id]/exists
only opens up the Papercups dashboard but /api/customers/[id]/exists
does return
{
"data": true
}
as /exists
is defined in the /api
scope only:
papercups/lib/chat_api_web/router.ex
Line 51 in 1ad023a
from papercups.
Have you checked if metadata field was filled when you update it or does it nullify the current metadata value
from papercups.
There's no metadata (null
) and I'm trying to add some but it always returns null
from papercups.
Hey @jeepers3327! Do you think you could put up a PR with this fix pls?
from papercups.
My apologies @CharlesMangwa for delay PR , I've been away for about a month due to unforeseen events.
from papercups.
No worries @jeepers3327! Take care of yourself first, the PR can wait 🙌
from papercups.
Closed by #1000 (comment).
from papercups.
Related Issues (20)
- Dev question HOT 1
- SMTP adapter is broken in Docker image
- Pull Request Preview Environments for increasing maintainer productivity
- Integrate pull request preview environments
- Deploy to Heroku button HOT 2
- Heroku one click deploy failed
- Upload fails from chat widget. HOT 7
- Ability to close live chat sessions from Mattermost
- BUG : In chat window the sending button dose not have an outline.
- Is this repo still maintained?
- Introducing new one-click deployment option (Elestio)
- Disable file upload
- It's possible to change the referrer meta field manually?
- Mark as unread HOT 1
- Reply from Slack integration doesn't forward incoming message to the Slack channel HOT 2
- Slack Interactivity Request URL for buttons to work
- More Detailed Instructions for Deploying to AWS
- webhook via ngrok not challenged - local setup
- Incomplete docs, missing a few keys to getting storytime to work. (listed them here)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from papercups.