Skip to content
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

Functionality to capture user activities #23

Merged
merged 15 commits into from
May 8, 2024

Conversation

Sachinbisht27
Copy link
Member

@Sachinbisht27 Sachinbisht27 commented May 2, 2024

#17

Please complete the following steps and check these boxes before filing your PR:

Types of changes

  • Bug fix (a change which fixes an issue)
  • New feature (a change which adds functionality)

Short description of what this resolves:

Changes contain:

  • Handling of webhook to get user activity details
  • Addition of the logic to create a new entry in the user activity table.
  • Logic to update the details in the same entry once the flow starts, is successful and is complete.

Testing payloads:

  • For activity started:
{
  "contact": {
    "id": 15356,
    "name": "User Name",
    "fields": {
      "dost_content_completed": {
        "inserted_at": "2024-04-19T11:44:41.961644Z",
        "label": "dost_content_completed",
        "type": "string",
        "value": "activity_1_sent"
      },
      "flow_execution_date": {
        "inserted_at": "2023-03-22T07:52:03.097151Z",
        "label": "flow_execution_date",
        "type": "string",
        "value": "Invalid Code"
      },
      "activity_1_started": {
        "label": "activity_1_started",
        "type": "string",
        "value": "true",
        "inserted_at": "2024-04-29T04:32:45.688102Z"
      },
      "last_flow": {
        "inserted_at": "2023-03-22T07:40:27.888117Z",
        "label": "last_flow",
        "type": "string",
        "value": "AWS_1"
      }
    },
    "phone": "+911234567890"
  },
  "current_time": "@calendar",
  "custom_key": "custom_value",
  "flow_status": "started",
  "flow_id": "14194",
  "flow_name": "Glific_Integration_Test_Flow",
  "flow_type": "activity",
  "flow_uuid": "3dddce1e-b76d-42d8-834b-964d70e3a0f9",
  "organization_id": 11,
  "activity_1_started": "yes",
  "results": {
    "flow_keyword": {
      "category": "draft:whatsappinit",
      "input": "draftwhatsappinit",
      "inserted_at": "2024-04-29T04:32:45.610016Z"
    }
  }
}
  • For activity suceeded:
{
  "contact": {
    "id": 15356,
    "name": "User Name",
    "fields": {
      "dost_content_completed": {
        "inserted_at": "2024-04-19T11:44:41.961644Z",
        "label": "dost_content_completed",
        "type": "string",
        "value": "activity_1_sent"
      },
      "flow_execution_date": {
        "inserted_at": "2023-03-22T07:52:03.097151Z",
        "label": "flow_execution_date",
        "type": "string",
        "value": "Invalid Code"
      },
      "activity_1_success": {
        "label": "activity_1_success",
        "type": "string",
        "value": "true",
        "inserted_at": "2024-04-29T04:32:45.688102Z"
      },
      "last_flow": {
        "inserted_at": "2023-03-22T07:40:27.888117Z",
        "label": "last_flow",
        "type": "string",
        "value": "AWS_1"
      }
    },
    "phone": "+911234567890"
  },
  "current_time": "@calendar",
  "custom_key": "custom_value",
  "flow_status": "started",
  "flow_id": "14194",
  "flow_name": "Glific_Integration_Test_Flow",
  "flow_type": "activity",
  "flow_uuid": "3dddce1e-b76d-42d8-834b-964d70e3a0f9",
  "organization_id": 11,
  "activity_1_success": "yes",
  "results": {
    "flow_keyword": {
      "category": "draft:whatsappinit",
      "input": "draftwhatsappinit",
      "inserted_at": "2024-04-29T04:32:45.610016Z"
    }
  }
}
  • For activity completed:
{
  "contact": {
    "id": 15356,
    "name": "User Name",
    "fields": {
      "dost_content_completed": {
        "inserted_at": "2024-04-19T11:44:41.961644Z",
        "label": "dost_content_completed",
        "type": "string",
        "value": "activity_1_sent"
      },
      "flow_execution_date": {
        "inserted_at": "2023-03-22T07:52:03.097151Z",
        "label": "flow_execution_date",
        "type": "string",
        "value": "Invalid Code"
      },
      "activity_1_completed": {
        "label": "activity_1_completed",
        "type": "string",
        "value": "true",
        "inserted_at": "2024-04-29T04:32:45.688102Z"
      },
      "last_flow": {
        "inserted_at": "2023-03-22T07:40:27.888117Z",
        "label": "last_flow",
        "type": "string",
        "value": "AWS_1"
      }
    },
    "phone": "+911234567890"
  },
  "current_time": "@calendar",
  "custom_key": "custom_value",
  "flow_id": "14194",
  "flow_name": "Glific_Integration_Test_Flow",
  "flow_type": "activity",
  "flow_status": "completed",
  "flow_uuid": "3dddce1e-b76d-42d8-834b-964d70e3a0f9",
  "organization_id": 11,
  "activity_1_completed": "yes",
  "results": {
    "flow_keyword": {
      "category": "draft:whatsappinit",
      "input": "draftwhatsappinit",
      "inserted_at": "2024-04-29T04:32:45.610016Z"
    }
  }
}

Checklist:

  • I have performed a self-review of my own code.
  • The code follows the style guidelines of this project.
  • The code changes are passing the CI checks
  • I have documented my code wherever required.
  • The changes requires a change to the documentation.
  • I have updated the documentation based on the my changes.
  • I have added tests to cover my changes (if not applicable, please state why)
  • All new and existing tests are passing.\

@Sachinbisht27 Sachinbisht27 marked this pull request as ready for review May 3, 2024 12:04
@Sachinbisht27 Sachinbisht27 requested a review from Satendra-SR May 3, 2024 12:04
@Sachinbisht27 Sachinbisht27 self-assigned this May 3, 2024
Copy link
Member

@Satendra-SR Satendra-SR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sachinbisht27 a few changes are required. Have a look

.first()
)

def get_succeeded_activity_for_user(self, user_id, user_phone):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

if not today_flow_log:
if flow_status == self.class_model.FlowRunStatus.COMPLETED:
user_flow_log = self.update_log(latest_flow_log)
else:
user_flow_log = self.create_log(flow_uuid, flow_name, flow_type)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should create a new log only if the start node is available - ie flow_status == "Started", thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks for the suggestion. Let me update that.

@Sachinbisht27 Sachinbisht27 requested a review from Satendra-SR May 7, 2024 17:44
Copy link
Member

@Satendra-SR Satendra-SR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sachinbisht27 a few comments before we merge the changes. Have a look

rev: v1.10.0
hooks:
- id: python-use-type-annotations
- repo: https://github.com/sondrelg/pep585-upgrade
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?
The GitHub repo is archived now, if this is helpful , we may need to find an alternative - https://github.com/sondrelg/pep585-upgrade

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was exploring some pre-commit hooks so, we can maintain the TypeHinting in the codebase. I found 2 hooks related to it so added them here. I can explore more if this one is archived now.

@Sachinbisht27 Sachinbisht27 merged commit cd1f937 into develop May 8, 2024
1 check passed
@Sachinbisht27 Sachinbisht27 deleted the feature/17-create-user-activities-service branch May 8, 2024 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants