From 788519ae8a73b226e0a55ed54852e99f5adbf3cf Mon Sep 17 00:00:00 2001 From: Florent Ravenel Date: Mon, 25 Sep 2023 18:06:42 +0200 Subject: [PATCH 1/4] feat(HubSpot): Add Chat about your last deals --- .../HubSpot_Chat_about_your_last_deals.ipynb | 252 ++++++++++++++++++ 1 file changed, 252 insertions(+) create mode 100644 HubSpot/HubSpot_Chat_about_your_last_deals.ipynb diff --git a/HubSpot/HubSpot_Chat_about_your_last_deals.ipynb b/HubSpot/HubSpot_Chat_about_your_last_deals.ipynb new file mode 100644 index 0000000000..3c88b38a8d --- /dev/null +++ b/HubSpot/HubSpot_Chat_about_your_last_deals.ipynb @@ -0,0 +1,252 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "d2e34832-b1e9-4cd1-ac74-a00dead5dc56", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "\"Naas\"" + ] + }, + { + "cell_type": "markdown", + "id": "182eb9cc-7fe5-4a96-9761-d1f631825a60", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# HubSpot - Chat about your last deals" + ] + }, + { + "cell_type": "markdown", + "id": "639b3515-7d32-4382-a7d9-5f5fa85366ee", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Tags:** #hubspot #chat #deals #last #discussion #conversation" + ] + }, + { + "cell_type": "markdown", + "id": "4363e628-6e22-40d8-bd6a-06cf89c76d5a", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Author:** [Florent Ravenel](https://www.linkedin.com/in/florent-ravenel)" + ] + }, + { + "cell_type": "markdown", + "id": "a60ac146-ffa4-41e6-b7ba-d6447478e613", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Last update:** 2023-09-25 (Created: 2023-09-25)" + ] + }, + { + "cell_type": "markdown", + "id": "bb50c25d-1933-45d4-ae12-acf488bdf130", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Description:** This notebook will help you to chat about your last deals with HubSpot. It will provide you with the necessary tools to discuss and analyze your deals." + ] + }, + { + "cell_type": "markdown", + "id": "106e2c3d-0618-4efa-8ed3-7ad6d87c4e6b", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**References:**\n- [HubSpot Documentation](https://knowledge.hubspot.com/articles/kcs_article/deals/how-to-use-deals-in-hubspot)\n- [HubSpot API Reference](https://developers.hubspot.com/docs/methods/deals/get_deals)" + ] + }, + { + "cell_type": "markdown", + "id": "21813711-0d2f-459b-b007-ba043e1db61f", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "6b5c040d-7db5-4f35-a0b6-67585ce30982", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "acd4f387-37e0-48dd-83f6-58d53b0d23bb", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": "import requests\nimport json", + "outputs": [] + }, + { + "cell_type": "markdown", + "id": "008aee68-01f6-45c0-8187-e0599bf94767", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Setup variables\n- **api_key**: API key to access HubSpot API. [How to get an API key?](https://knowledge.hubspot.com/articles/kcs_article/integrations/how-do-i-get-my-hubspot-api-key)\n- **deal_id**: ID of the deal to be discussed" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "82eced2a-b85e-46ac-a0b4-605eb6cb54c8", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": "api_key = \"\"\ndeal_id = \"\"", + "outputs": [] + }, + { + "cell_type": "markdown", + "id": "c057ab90-3977-4dd8-84c4-e2e076b4c8d7", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "6455b000-444d-4a6d-bb23-5256a580d057", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Get deal information" + ] + }, + { + "cell_type": "markdown", + "id": "99603978-853d-4270-ac58-63c42b6cfa6d", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "Retrieve the deal information from HubSpot API." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e118fe6b-eb64-4418-9f78-adc15355e49d", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": "url = f\"https://api.hubapi.com/deals/v1/deal/{deal_id}?hapikey={api_key}\"\nresponse = requests.get(url)\ndeal_info = json.loads(response.text)", + "outputs": [] + }, + { + "cell_type": "markdown", + "id": "7e594ca8-f96c-4fb0-9f92-941fddc5060b", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "5b3c917f-9545-40a0-b2e3-6b99ed027de2", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Display result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bab6640a-8da8-4637-be33-734f1c09d3b6", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": "print(deal_info)", + "outputs": [] + }, + { + "cell_type": "markdown", + "id": "fb39a75e-176a-41c3-a394-2988b49b80e3", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + " " + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.6" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": {}, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} \ No newline at end of file From 929d078fa1384044b71e1afce4fe4fd24d1549fa Mon Sep 17 00:00:00 2001 From: Florent Ravenel Date: Mon, 25 Sep 2023 18:26:27 +0200 Subject: [PATCH 2/4] feat: add new template chat about a deal --- HubSpot/HubSpot_Chat_about_a_deal.ipynb | 521 ++++++++++++++++++ .../HubSpot_Chat_about_your_last_deals.ipynb | 252 --------- 2 files changed, 521 insertions(+), 252 deletions(-) create mode 100644 HubSpot/HubSpot_Chat_about_a_deal.ipynb delete mode 100644 HubSpot/HubSpot_Chat_about_your_last_deals.ipynb diff --git a/HubSpot/HubSpot_Chat_about_a_deal.ipynb b/HubSpot/HubSpot_Chat_about_a_deal.ipynb new file mode 100644 index 0000000000..ada9f2dd24 --- /dev/null +++ b/HubSpot/HubSpot_Chat_about_a_deal.ipynb @@ -0,0 +1,521 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "d2e34832-b1e9-4cd1-ac74-a00dead5dc56", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "\"Naas\"" + ] + }, + { + "cell_type": "markdown", + "id": "182eb9cc-7fe5-4a96-9761-d1f631825a60", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# HubSpot - Chat about a deal" + ] + }, + { + "cell_type": "markdown", + "id": "639b3515-7d32-4382-a7d9-5f5fa85366ee", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Tags:** #hubspot #chat #deals #last #discussion #conversation" + ] + }, + { + "cell_type": "markdown", + "id": "4363e628-6e22-40d8-bd6a-06cf89c76d5a", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Author:** [Florent Ravenel](https://www.linkedin.com/in/florent-ravenel)" + ] + }, + { + "cell_type": "markdown", + "id": "a60ac146-ffa4-41e6-b7ba-d6447478e613", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Last update:** 2023-09-25 (Created: 2023-09-25)" + ] + }, + { + "cell_type": "markdown", + "id": "bb50c25d-1933-45d4-ae12-acf488bdf130", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Description:** This notebook assists you in discussing a deal on HubSpot by providing essential insights about the deal and its recent activities. This information will enable you to plan your next steps effectively." + ] + }, + { + "cell_type": "markdown", + "id": "3fb3f310-bd86-41ac-b4c1-790472bc04d1", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "02522295-f0cc-4524-93fb-2b2ab5ac480e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "import requests\n", + "import naas\n", + "from naas_drivers import hubspot, naas_chat_plugin\n", + "import pandas as pd\n", + "import os\n", + "pd.set_option('display.max_colwidth', None)" + ] + }, + { + "cell_type": "markdown", + "id": "b8dcccd0-539d-4719-8c4b-269fd2ed1de4", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Setup variables\n", + "**Mandatory**\n", + "\n", + "[Get your HubSpot Access token](https://knowledge.hubspot.com/articles/kcs_article/integrations/how-do-i-get-my-hubspot-api-key)\n", + "- `hs_access_token`: This variable stores an access token used for accessing the HubSpot API.\n", + "- `deal_url`: This variable stores the HubSpot deal URL.\n", + "\n", + "**Optional**\n", + "- `deal_properties`: It represents the list of properties to retrieve from your deal\n", + "- `associations`: It represents the list of associations to get from your deal\n", + "- `plugin_name`: It represents the name of the plugin." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f3708001-f591-48ef-aba6-6ff184092bbc", + "metadata": { + "papermill": {}, + "tags": [ + "parameters" + ] + }, + "outputs": [], + "source": [ + "# Mandatory\n", + "hs_access_token = naas.secret.get(\"HS_ACCESS_TOKEN\") or \"YOUR_HS_ACCESS_TOKEN\"\n", + "deal_url = \"https://app.hubspot.com/contacts/2474088/record/0-3/15220482319/\" # \"https://app.hubspot.com/contacts/xxxxx/record/0-1/xxxxx\"\n", + "\n", + "# Optional\n", + "deal_properties = [\"hs_object_id\", \"dealname\", 'amount']\n", + "associations = [\"notes\", \"emails\", \"meetings\", \"communications\"]\n", + "plugin_name = \"Sales Agent\"" + ] + }, + { + "cell_type": "markdown", + "id": "af3b118f-91aa-4426-a1fb-4358e4eaf10b", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "bba4a41a-3eee-4446-9211-6fe2522d27f7", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "#### Engineer system prompt\n", + "We used Playground to refined it: https://platform.openai.com/playground?mode=chat&model=gpt-4" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2535ae58-b7c4-46a0-8141-d0adb1c3c157", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "system_prompt = f\"\"\"\n", + "Act as a Sales Agent expert in analyzing conversations and extracting action items.\n", + "\n", + "Please present the deal giving access to it with the URL: [URL] and then review the text and identify any tasks, assignments, or actions needed to be done.\n", + "These could be tasks assigned to specific individuals, or general actions that the group has decided to take.\n", + "Please list these action items clearly and concisely.\n", + "\n", + "Data: [ACTIVITIES]\n", + "\"\"\"" + ] + }, + { + "cell_type": "markdown", + "id": "0c3b0fbe-0caf-42f2-af6b-68ba241fa22e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Get deal ID from URL" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5903fe72-265c-4a31-bacd-f5c04d4aee7a", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "def get_contact_ID_from_URL(url):\n", + " # Init\n", + " uid = url\n", + " \n", + " # Check if URL is valid\n", + " if not url.startswith(\"https://app.hubspot.com/contacts/\"):\n", + " raise BaseException(\"HubSpot URL Invalid! It must start by https://app.hubspot.com/contacts/\")\n", + " \n", + " # Split URL to get ID\n", + " if \"/record/0-3/\" in url:\n", + " uid = url.split(\"/record/0-3/\")[-1].split(\"/\")[0]\n", + " return uid\n", + "\n", + "deal_id = get_contact_ID_from_URL(deal_url)\n", + "print(\"Deal ID:\", deal_id)" + ] + }, + { + "cell_type": "markdown", + "id": "55dceacb-7f01-4936-85d3-fe0e616dafce", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Get contact details" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6096ec3d-23bb-4632-b2d8-efc1c702fa8e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "def retrieve_object_details(\n", + " token,\n", + " object_id,\n", + " object_type,\n", + " properties=None,\n", + "):\n", + " # Init\n", + " data = []\n", + " params = {\n", + " \"archived\": \"false\"\n", + " }\n", + " \n", + " # Requests\n", + " if properties:\n", + " params[\"properties\"] = properties\n", + " headers = {\n", + " \"Content-Type\": \"application/json\",\n", + " \"Authorization\": f\"Bearer {token}\"\n", + " }\n", + " url = f\"https://api.hubapi.com/crm/v3/objects/{object_type}/{object_id}\"\n", + " \n", + " # Response\n", + " res = requests.get(url, headers=headers, params=params)\n", + " if res.status_code == 200:\n", + " data = res.json().get(\"properties\")\n", + " else:\n", + " print(res.text)\n", + " return pd.DataFrame([data])\n", + "\n", + "def create_activity_df(\n", + " token,\n", + " object_id,\n", + " activity,\n", + " properties_dict=None,\n", + "):\n", + " # Init\n", + " properties = [x for x in properties_dict]\n", + " \n", + " # List activities\n", + " df = retrieve_object_details(\n", + " token,\n", + " object_id,\n", + " activity,\n", + " properties\n", + " )\n", + " if len(df) > 0:\n", + " df = df[properties]\n", + " \n", + " if len(df) > 0:\n", + " df = df.rename(columns=properties_dict)\n", + " if 'activity_type' not in df:\n", + " df.insert(loc=1, column=\"activity_type\", value=activity.upper())\n", + " \n", + " return df.reset_index(drop=True)\n", + "\n", + "def get_details(\n", + " hs_access_token,\n", + " hubspot_id,\n", + " properties,\n", + " associations\n", + "):\n", + " # Init\n", + " message = \"DEAL:\\n\"\n", + " df = pd.DataFrame()\n", + " \n", + " # Get object\n", + " obj = hubspot.connect(hs_access_token).deals.get(\n", + " hubspot_id,\n", + " hs_properties=properties,\n", + " hs_associations=associations\n", + " )\n", + " \n", + " # Get properties\n", + " obj_properties = obj.get(\"properties\")\n", + " for p in properties:\n", + " message = f\"{message}- {p}: {obj_properties.get(p)}\\n\"\n", + " \n", + " # Get contact associations\n", + " obj_associations = obj.get(\"associations\")\n", + " for a in obj_associations:\n", + " results = obj_associations.get(a).get(\"results\")\n", + " for r in results:\n", + " if a == \"communications\":\n", + " properties_dict = {\n", + " \"hs_object_id\": \"activity_hs_id\",\n", + " \"hs_timestamp\": \"activity_date\",\n", + " \"hs_communication_channel_type\": \"activity_type\",\n", + " \"hs_body_preview\": \"activity_content\"\n", + " }\n", + " elif a == \"meetings\":\n", + " properties_dict = {\n", + " \"hs_object_id\": \"activity_hs_id\",\n", + " \"hs_timestamp\": \"activity_date\",\n", + " \"hs_meeting_title\": \"activity_content\"\n", + " }\n", + " else:\n", + " properties_dict = {\n", + " \"hs_object_id\": \"activity_hs_id\",\n", + " \"hs_timestamp\": \"activity_date\",\n", + " \"hs_body_preview\": \"activity_content\"\n", + " }\n", + " association_id = r.get(\"id\")\n", + " \n", + " # Create activity df\n", + " tmp_df = create_activity_df(\n", + " hs_access_token,\n", + " association_id,\n", + " a,\n", + " properties_dict\n", + " )\n", + " df = pd.concat([df, tmp_df])\n", + " \n", + " # Cleaning df\n", + " if len(df) > 0:\n", + " # Exclude empty or None value\n", + " df = df[~(df[\"activity_content\"].astype(str).isin([\"None\"]))]\n", + "\n", + " # Format date\n", + " df[\"activity_date\"] = pd.to_datetime(df[\"activity_date\"]).dt.strftime(\"%Y-%m-%d %H:%M:%S\")\n", + " df = df.sort_values(by=\"activity_date\", ascending=False).reset_index(drop=True)\n", + " \n", + " # Create activity message\n", + " message = f\"{message}\\nACTIVITIES:\\n\"\n", + " for row in df.itertuples():\n", + " activity_date = row.activity_date\n", + " activity_type = row.activity_type\n", + " activity_content = row.activity_content.replace(\"\\xa0\\u200c\", \"\")\n", + " message = f\"{message}-{activity_date}: {activity_type} - {activity_content}\\n\"\n", + " return message, df.reset_index(drop=True)\n", + "\n", + "brief, df_activity = get_details(\n", + " hs_access_token,\n", + " deal_id,\n", + " deal_properties,\n", + " associations\n", + ")\n", + "print(brief)" + ] + }, + { + "cell_type": "markdown", + "id": "aa2d3a26-c957-4c70-bc0d-68be83eb28cc", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "f10c7bd1-448c-434a-8b9c-93e16fa5feb3", + "metadata": { + "execution": { + "iopub.execute_input": "2023-08-21T14:13:58.779716Z", + "iopub.status.busy": "2023-08-21T14:13:58.779474Z", + "iopub.status.idle": "2023-08-21T14:13:58.784746Z", + "shell.execute_reply": "2023-08-21T14:13:58.784135Z", + "shell.execute_reply.started": "2023-08-21T14:13:58.779693Z" + }, + "papermill": {}, + "tags": [] + }, + "source": [ + "### Save DataFrame to CSV" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8cb21df7-3e0d-492c-a252-15bd9063905e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "df_activity.to_csv(f\"Deal_activity_{deal_id}.csv\", index=False)" + ] + }, + { + "cell_type": "markdown", + "id": "f876c2a1-116f-49d1-bc97-68dd49ed65b1", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Generate plugin" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c9f38695-12ad-4927-bb67-5b02b6ec8777", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "# System prompt\n", + "system_prompt = system_prompt.replace(\"[ACTIVITIES]\", brief).replace(\"[URL]\", deal_url)\n", + "\n", + "# Plugin file path\n", + "plugin_file_path = naas_chat_plugin.create_plugin(\n", + " plugin_name,\n", + " system_prompt,\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "713397d3-0479-4a45-9517-9d52d003b2b6", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Create asset\n", + "You can now use in your Naas Chat by copy/pasting the URL after the command `/use `" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6b7daf0f-dcfc-4206-9d71-f11ae9448041", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "naas.asset.add(plugin_file_path, params={\"inline\": True})" + ] + }, + { + "cell_type": "markdown", + "id": "fb39a75e-176a-41c3-a394-2988b49b80e3", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + " " + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.6" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": {}, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/HubSpot/HubSpot_Chat_about_your_last_deals.ipynb b/HubSpot/HubSpot_Chat_about_your_last_deals.ipynb deleted file mode 100644 index 3c88b38a8d..0000000000 --- a/HubSpot/HubSpot_Chat_about_your_last_deals.ipynb +++ /dev/null @@ -1,252 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "d2e34832-b1e9-4cd1-ac74-a00dead5dc56", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "\"Naas\"" - ] - }, - { - "cell_type": "markdown", - "id": "182eb9cc-7fe5-4a96-9761-d1f631825a60", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "# HubSpot - Chat about your last deals" - ] - }, - { - "cell_type": "markdown", - "id": "639b3515-7d32-4382-a7d9-5f5fa85366ee", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "**Tags:** #hubspot #chat #deals #last #discussion #conversation" - ] - }, - { - "cell_type": "markdown", - "id": "4363e628-6e22-40d8-bd6a-06cf89c76d5a", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "**Author:** [Florent Ravenel](https://www.linkedin.com/in/florent-ravenel)" - ] - }, - { - "cell_type": "markdown", - "id": "a60ac146-ffa4-41e6-b7ba-d6447478e613", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "**Last update:** 2023-09-25 (Created: 2023-09-25)" - ] - }, - { - "cell_type": "markdown", - "id": "bb50c25d-1933-45d4-ae12-acf488bdf130", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "**Description:** This notebook will help you to chat about your last deals with HubSpot. It will provide you with the necessary tools to discuss and analyze your deals." - ] - }, - { - "cell_type": "markdown", - "id": "106e2c3d-0618-4efa-8ed3-7ad6d87c4e6b", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "**References:**\n- [HubSpot Documentation](https://knowledge.hubspot.com/articles/kcs_article/deals/how-to-use-deals-in-hubspot)\n- [HubSpot API Reference](https://developers.hubspot.com/docs/methods/deals/get_deals)" - ] - }, - { - "cell_type": "markdown", - "id": "21813711-0d2f-459b-b007-ba043e1db61f", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "## Input" - ] - }, - { - "cell_type": "markdown", - "id": "6b5c040d-7db5-4f35-a0b6-67585ce30982", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "### Import libraries" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "acd4f387-37e0-48dd-83f6-58d53b0d23bb", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": "import requests\nimport json", - "outputs": [] - }, - { - "cell_type": "markdown", - "id": "008aee68-01f6-45c0-8187-e0599bf94767", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "### Setup variables\n- **api_key**: API key to access HubSpot API. [How to get an API key?](https://knowledge.hubspot.com/articles/kcs_article/integrations/how-do-i-get-my-hubspot-api-key)\n- **deal_id**: ID of the deal to be discussed" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "82eced2a-b85e-46ac-a0b4-605eb6cb54c8", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": "api_key = \"\"\ndeal_id = \"\"", - "outputs": [] - }, - { - "cell_type": "markdown", - "id": "c057ab90-3977-4dd8-84c4-e2e076b4c8d7", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "## Model" - ] - }, - { - "cell_type": "markdown", - "id": "6455b000-444d-4a6d-bb23-5256a580d057", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "### Get deal information" - ] - }, - { - "cell_type": "markdown", - "id": "99603978-853d-4270-ac58-63c42b6cfa6d", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "Retrieve the deal information from HubSpot API." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "e118fe6b-eb64-4418-9f78-adc15355e49d", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": "url = f\"https://api.hubapi.com/deals/v1/deal/{deal_id}?hapikey={api_key}\"\nresponse = requests.get(url)\ndeal_info = json.loads(response.text)", - "outputs": [] - }, - { - "cell_type": "markdown", - "id": "7e594ca8-f96c-4fb0-9f92-941fddc5060b", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "## Output" - ] - }, - { - "cell_type": "markdown", - "id": "5b3c917f-9545-40a0-b2e3-6b99ed027de2", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "### Display result" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "bab6640a-8da8-4637-be33-734f1c09d3b6", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": "print(deal_info)", - "outputs": [] - }, - { - "cell_type": "markdown", - "id": "fb39a75e-176a-41c3-a394-2988b49b80e3", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - " " - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.6" - }, - "widgets": { - "application/vnd.jupyter.widget-state+json": { - "state": {}, - "version_major": 2, - "version_minor": 0 - } - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} \ No newline at end of file From 45ef45766b2b170638571685e86adbc7169a0ab5 Mon Sep 17 00:00:00 2001 From: Florent Ravenel Date: Mon, 25 Sep 2023 18:26:50 +0200 Subject: [PATCH 3/4] fix: error to save plugin with variable contact_id --- HubSpot/HubSpot_Get_deal_brief.ipynb | 96 ++++++++++++++++++++++++---- 1 file changed, 83 insertions(+), 13 deletions(-) diff --git a/HubSpot/HubSpot_Get_deal_brief.ipynb b/HubSpot/HubSpot_Get_deal_brief.ipynb index 7a4d84009a..35108674f1 100644 --- a/HubSpot/HubSpot_Get_deal_brief.ipynb +++ b/HubSpot/HubSpot_Get_deal_brief.ipynb @@ -105,9 +105,16 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "a3fad6df-27f3-4e13-a934-083468860bf3", "metadata": { + "execution": { + "iopub.execute_input": "2023-09-25T16:07:29.545156Z", + "iopub.status.busy": "2023-09-25T16:07:29.544912Z", + "iopub.status.idle": "2023-09-25T16:07:35.923044Z", + "shell.execute_reply": "2023-09-25T16:07:35.922343Z", + "shell.execute_reply.started": "2023-09-25T16:07:29.545084Z" + }, "papermill": {}, "tags": [] }, @@ -115,7 +122,7 @@ "source": [ "import requests\n", "import naas\n", - "from naas_drivers import hubspot, naas_chat_plugin\n", + "from naas_drivers import hubspot\n", "import pandas as pd\n", "import os\n", "pd.set_option('display.max_colwidth', None)" @@ -144,9 +151,16 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "13df3457-9ca4-4a77-ace7-2cd5a386362d", "metadata": { + "execution": { + "iopub.execute_input": "2023-09-25T16:07:35.932504Z", + "iopub.status.busy": "2023-09-25T16:07:35.932259Z", + "iopub.status.idle": "2023-09-25T16:07:36.080220Z", + "shell.execute_reply": "2023-09-25T16:07:36.079585Z", + "shell.execute_reply.started": "2023-09-25T16:07:35.932481Z" + }, "papermill": {}, "tags": [ "parameters" @@ -188,13 +202,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "c3588e3a-0829-485a-81c5-bcde7f137549", "metadata": { + "execution": { + "iopub.execute_input": "2023-09-25T16:07:36.083608Z", + "iopub.status.busy": "2023-09-25T16:07:36.083186Z", + "iopub.status.idle": "2023-09-25T16:07:36.094488Z", + "shell.execute_reply": "2023-09-25T16:07:36.093862Z", + "shell.execute_reply.started": "2023-09-25T16:07:36.083569Z" + }, "papermill": {}, "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Deal ID: 15220482319\n" + ] + } + ], "source": [ "def get_contact_ID_from_URL(url):\n", " # Init\n", @@ -226,13 +255,39 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "9c5c7fdf-be1e-4b0c-8cc2-705b460d00f3", "metadata": { + "execution": { + "iopub.execute_input": "2023-09-25T16:07:36.096036Z", + "iopub.status.busy": "2023-09-25T16:07:36.095607Z", + "iopub.status.idle": "2023-09-25T16:07:37.826473Z", + "shell.execute_reply": "2023-09-25T16:07:37.825810Z", + "shell.execute_reply.started": "2023-09-25T16:07:36.096004Z" + }, "papermill": {}, "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "DEAL:\n", + "- hs_object_id: 15220482319\n", + "- dealname: Agicap X Icelex connexion Quadra\n", + "- dealstage: 8432674\n", + "- amount: None\n", + "\n", + "ACTIVITIES:\n", + "-2023-09-19 07:30:00: EMAILS - Bonjour David, Merci de votre retour.  J'ai essayé de me connecter à CEGIDLife mais je n'y ai pas eu accès. (impression d' écran ci-dessous) Pourriez-vous svp me fournir la procédure d'accès? Cordialement, Florent\n", + "-2023-09-18 16:46:00: EMAILS - Bonsoir,   Avec mes excuses, la console Admin a été inopérante un temps et je n’ai pu supprimer un compte pour créer le vôtre.   Ci-joint le fichier contenant l’identifiant et le 1er mot de passe à changer à la 1e connexion.   Je créerai votre accès dossier à Quadra demain.   Bien cordialement, David CAMUS Responsable CSP Comptabilité Groupe 11 rue Marcel Sembat - 94140 ALFORTVILLE - FRANCE Tel.: + 33 (0)1 41 79 76 89 – Mob.: +33 (0)6 80 42 57 43 dcamus@icelec.com     Visitez notre site web : www.icegroupe.com   Devez-vous vraiment imprimer ce courriel ? Pensons environnement.   Ce message et les éventuelles pièces attachées sont confidentiels. Si vous n'êtes pas dans la liste des destinataires, veuillez informer l'expéditeur immédiatement et ne pas divulguer le contenu à une tierce personne, ne pas l'utiliser pour quelque raison que ce soit, ne pas stocker ou copier l'information qu'il contient sur un quelconque support. Les précautions raisonnables ont  été prises pour éviter que des virus ne soient transmis par ce message mais il vous appartient de mettre en place des mesures de sécurité destinées à détecter et éradiquer la présence d’un éventuel virus. Nous ne saurions être tenus responsables pour tout dommage causé par la transmission d’un virus et/ou la contamination de votre système informatique. Le réseau internet ne permettant pas d'assurer l’intégrité de ce message, l’expéditeur décline toute responsabilité au cas où il aurait été intercepté ou modifié par quiconque.    \n", + "-2023-09-15 08:23:00: EMAILS - Bonjour à tous,  Monsieur Camu, je me permets de créer cette boucle de mail afin de savoir si vous avez pu créer les accès pour la société Naas afin qu'il puisse faire une analyse de la connexion de votre système à Agicap ? Je reste disponible. Bien à vous,  Pierre -- Pierre Reffay Responsable commercial   pierre.reffay@agicap.com ++33 6 18 10 93 21\n", + "-2023-09-13 09:26:00: EMAILS - Agicap X Icelex connexion Quadra   Bonjour, Ci-joint, le lien de notre visio : https://meet.google.com/abi-fswr-ruq?authuser=0 A tout de suite, Pierre Participer avec Google Meet Lien de la réunion meet.google.com/abi-fswr-ruq Participer par téléphone (FR) +33 1 87 40 40 99 CODE SECRET: 593083222 Plus de numéros de téléphone Agicap X Icelex connexion Quadra mercredi 13 sept. 2023 ⋅ 11:30am – 12pm (Heure d’Europe centrale - Paris) Invités pierre.reffay@agicap.com - organisateur plefeuvre@icelec.com maxime@naas.ai florent@naas.ai dcamus@icelec.com tbenslimane@icelec.com\n", + "\n" + ] + } + ], "source": [ "def retrieve_object_details(\n", " token,\n", @@ -404,20 +459,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "62e3f7af-5383-45fc-b5ec-31796a179f34", "metadata": { + "execution": { + "iopub.execute_input": "2023-09-25T16:07:50.800708Z", + "iopub.status.busy": "2023-09-25T16:07:50.800374Z", + "iopub.status.idle": "2023-09-25T16:07:50.832507Z", + "shell.execute_reply": "2023-09-25T16:07:50.831893Z", + "shell.execute_reply.started": "2023-09-25T16:07:50.800676Z" + }, "papermill": {}, "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "File successfully saved: hubspot/15220482319_deal_brief.txt\n" + ] + } + ], "source": [ - "def save_txt(output_dir, contact_id, txt):\n", + "def save_txt(output_dir, husbspot_id, txt):\n", " # Create dirs\n", " os.makedirs(output_dir, exist_ok=True)\n", " \n", " # Create path\n", - " file_path = os.path.join(output_dir, f\"{contact_id}_deal_brief.txt\")\n", + " file_path = os.path.join(output_dir, f\"{husbspot_id}_deal_brief.txt\")\n", " \n", " # Save file\n", " file = open(file_path, 'w') # Open the file in write mode ('w')\n", @@ -425,7 +495,7 @@ " file.close() # Always remember to close the file\n", " print(f\"File successfully saved: {file_path}\")\n", " \n", - "save_txt(output_dir, contact_id, brief)" + "save_txt(output_dir, deal_id, brief)" ] } ], @@ -467,4 +537,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} From da1cd3ba9391dd2293326bbb909ce9e7e40773f7 Mon Sep 17 00:00:00 2001 From: Florent Ravenel Date: Mon, 25 Sep 2023 18:28:58 +0200 Subject: [PATCH 4/4] fix: add cell ## Input --- HubSpot/HubSpot_Chat_about_a_deal.ipynb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/HubSpot/HubSpot_Chat_about_a_deal.ipynb b/HubSpot/HubSpot_Chat_about_a_deal.ipynb index ada9f2dd24..0cceb7b1b8 100644 --- a/HubSpot/HubSpot_Chat_about_a_deal.ipynb +++ b/HubSpot/HubSpot_Chat_about_a_deal.ipynb @@ -95,6 +95,14 @@ "pd.set_option('display.max_colwidth', None)" ] }, + { + "cell_type": "markdown", + "id": "4f5998fe-fc54-42c5-920e-3533a4002c7c", + "metadata": {}, + "source": [ + "## Input" + ] + }, { "cell_type": "markdown", "id": "b8dcccd0-539d-4719-8c4b-269fd2ed1de4",