-
-
Notifications
You must be signed in to change notification settings - Fork 131
Support Gift transaction event, map timeline events using customerSupportChat payload when available #184
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
Draft
NiklasRosenstein
wants to merge
8
commits into
master
Choose a base branch
from
183-process-gift-event
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Support Gift transaction event, map timeline events using customerSupportChat payload when available #184
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
49c51ca
Support Gift transaction event, map timeline events using customerSup…
NiklasRosenstein 84684e3
still raise UnsupportedEventError
NiklasRosenstein 69c5397
move logging of events that have no matching timeline event into Time…
NiklasRosenstein bcbf929
Merge branch 'master' into 183-process-gift-event
NiklasRosenstein f555381
satisfy mypy
NiklasRosenstein 69d819b
add warning log for debugging #173
NiklasRosenstein 66a75af
map `card_successful_verification` to new `PPEventType.OTHER`
NiklasRosenstein 0783fed
rename _types to types after uv 0.5.31
NiklasRosenstein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,13 @@ | ||
| import json | ||
| from datetime import datetime | ||
| from typing import Optional, cast | ||
|
|
||
| from .transactions import export_transactions | ||
| from .utils import get_logger | ||
| import jsonpath | ||
|
|
||
| from pytr.types import TimelineDetailV2, TimelineDetailV2_CustomerSupportChatAction | ||
|
|
||
| class UnsupportedEventError(Exception): | ||
| pass | ||
| from .transactions import export_transactions | ||
| from .utils import get_logger | ||
|
|
||
|
|
||
| class Timeline: | ||
|
|
@@ -39,7 +40,7 @@ async def get_next_timeline_transactions(self, response=None): | |
| for event in response["items"]: | ||
| if ( | ||
| self.max_age_timestamp == 0 | ||
| or datetime.fromisoformat(event["timestamp"][:19]).timestamp() >= self.max_age_timestamp | ||
| or datetime.fromisoformat(event["timestamp"]).timestamp() >= self.max_age_timestamp | ||
| ): | ||
| event["source"] = "timelineTransaction" | ||
| self.timeline_events[event["id"]] = event | ||
|
|
@@ -125,9 +126,19 @@ def process_timelineDetail(self, response, dl): | |
| create other_events.json, events_with_documents.json and account_transactions.csv | ||
| """ | ||
|
|
||
| event = self.timeline_events.get(response["id"], None) | ||
| # Find the ID of the corresponding timeline event. This is burried deep in the last section of the | ||
| # response that contains the customer support information. | ||
| support_action = get_customer_support_chat_action(response) | ||
| if support_action and (timeline_event_id := support_action["payload"]["contextParams"].get("timelineEventId")): | ||
| pass | ||
| else: | ||
| timeline_event_id = response["id"] | ||
|
|
||
| event = self.timeline_events.get(timeline_event_id, None) | ||
| if event is None: | ||
| raise UnsupportedEventError(response["id"]) | ||
| self.log.warning("Missing timeline event %r for detail: %s", timeline_event_id, json.dumps(response)) | ||
| self.skipped_detail += 1 | ||
| return | ||
|
Comment on lines
+139
to
+141
Collaborator
Author
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. Now that I have a better understanding of this code, I think this code makes more sense than what I introduced in #161. |
||
|
|
||
| self.received_detail += 1 | ||
| event["details"] = response | ||
|
|
@@ -205,3 +216,18 @@ def finish_timeline_details(self, dl): | |
| ) | ||
|
|
||
| dl.work_responses() | ||
|
|
||
|
|
||
| def get_customer_support_chat_action( | ||
| timeline_detail: TimelineDetailV2, | ||
| ) -> Optional[TimelineDetailV2_CustomerSupportChatAction]: | ||
| """ | ||
| From a `timelineDetailV2` object, find the `customerSupportChat` object. | ||
| """ | ||
|
|
||
| JSONPATH = '$.sections[*].data[?(@.detail.action.type == "customerSupportChat")].detail.action' | ||
|
|
||
| for action in jsonpath.finditer(JSONPATH, timeline_detail): | ||
| return cast(TimelineDetailV2_CustomerSupportChatAction, action.obj) | ||
|
|
||
| return None | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import Any, Literal, TypedDict | ||
|
|
||
| from typing_extensions import NotRequired | ||
|
|
||
|
|
||
| class TimelineDetailV2(TypedDict): | ||
| """ | ||
| Incomplete typed representation of the TR `timelineDetailV2` object. | ||
| """ | ||
|
|
||
| id: str | ||
| sections: list[TimelineDetailV2_Section] | ||
|
|
||
|
|
||
| class TimelineDetailV2_Section(TypedDict): | ||
| title: str | ||
| type: Literal["header", "table", "steps"] | ||
| data: dict[str, Any] | list[dict[str, Any]] | ||
|
|
||
|
|
||
| class TimelineDetailV2_CustomerSupportChatAction(TypedDict): | ||
| type: Literal["customerSupportChat"] | ||
| payload: TimelineDetailV2_CustomerSupportChatAction_Payload | ||
| style: str | ||
|
|
||
|
|
||
| class TimelineDetailV2_CustomerSupportChatAction_Payload(TypedDict): | ||
| contextParams: TimelineDetailV2_CustomerSupportChatAction_ContextParamms | ||
| contextCategory: str | ||
|
|
||
|
|
||
| class TimelineDetailV2_CustomerSupportChatAction_ContextParamms(TypedDict): | ||
| chat_flow_key: str | ||
| timelineEventId: NotRequired[str] | ||
| savingsPlanId: NotRequired[str] | ||
| primId: NotRequired[str] | ||
| groupId: NotRequired[str] | ||
| createdAt: NotRequired[str] | ||
| amount: NotRequired[str] | ||
| iban: NotRequired[str] | ||
| interestPayoutId: NotRequired[str] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import json | ||
|
|
||
| from pytr.timeline import get_customer_support_chat_action | ||
|
|
||
|
|
||
| def test__get_customer_support_chat_action() -> None: | ||
| with open("tests/sample_event.json", "r") as file: | ||
| sample_data = json.load(file) | ||
|
|
||
| data = get_customer_support_chat_action(sample_data["details"]) | ||
| assert data is not None | ||
| assert data == { | ||
| "payload": { | ||
| "contextParams": { | ||
| "timelineEventId": "d8a5aa3d-12a4-465a-90ad-3fca36eff19a", | ||
| "chat_flow_key": "NHC_0024_deposit_report_an_issue", | ||
| }, | ||
| "contextCategory": "NHC", | ||
| }, | ||
| "type": "customerSupportChat", | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not exactly sure yet if this is the right category to assign it to. In the
export_transactionsresult, it will be labelled asTransfer (Outbound).