Skip to content

Commit

Permalink
Merge pull request #90 from jupyter-naas/89-remove-connect-to-tools-f…
Browse files Browse the repository at this point in the history
…rom-commands

feat: remove connect to tools from commands + add commands in engine
  • Loading branch information
FlorentLvr authored Feb 12, 2024
2 parents 86819ae + 0d10c6f commit 831598b
Show file tree
Hide file tree
Showing 11 changed files with 2,630 additions and 70 deletions.
331 changes: 331 additions & 0 deletions models/finance-engine/core/tools/Stripe_Send_payment_link.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,331 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "84d9b100-6e5f-4c96-8164-06d574f7fa71",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"<img width=\"8%\" alt=\"Stripe.png\" src=\"https://raw.githubusercontent.com/jupyter-naas/awesome-notebooks/master/.github/assets/logos/Stripe.png\" style=\"border-radius: 15%\">"
]
},
{
"cell_type": "markdown",
"id": "fe7f0846-ce7f-43c9-8202-a90b9e29cd4c",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"# Stripe - Send payment link"
]
},
{
"cell_type": "markdown",
"id": "c0403ba8-62ef-4413-94d4-5b225a4ae7ac",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**Tags:** #stripe #finance #payment #command"
]
},
{
"cell_type": "markdown",
"id": "d295e708-adaa-45b8-911e-976451f36f80",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**Author:** [Florent Ravenel](https://www.linkedin.com/in/florent-ravenel/)"
]
},
{
"cell_type": "markdown",
"id": "03594f2a-572a-4303-9161-c8e6b6d42f17",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**Last update:** 2024-02-07 (Created: 2024-02-07)"
]
},
{
"cell_type": "markdown",
"id": "61edbaba-cd8f-43f2-b956-247d2408756f",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**Description:** This notebook sent a Stripe payment link to a new customer."
]
},
{
"cell_type": "markdown",
"id": "633cba7e-6805-4f74-bfb7-a57f316a1958",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**References:**\n",
"- [Stripe]()"
]
},
{
"cell_type": "markdown",
"id": "dd7865b3-eb7b-4755-9929-54ae4355ac46",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"## Input"
]
},
{
"cell_type": "markdown",
"id": "9db307ec-534b-47b4-a606-6cf4e9213d24",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Import libraries"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9de34e94-bcf2-40c1-8970-6a7e07f4917b",
"metadata": {
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"import naas"
]
},
{
"cell_type": "markdown",
"id": "18fe9773-ca11-4d15-b0c0-e3b86315415d",
"metadata": {
"papermill": {},
"tags": [
"variables"
]
},
"source": [
"### Setup variables\n",
"- `email`: [email protected]\n",
"- `product`: \"Naas Enterprise\"\n",
"- `amount`: 100\n",
"- `currency`: 'USD'\n",
"- `body`: This variable stores the body to be send by the webhook."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3d26d9bc-d873-4f81-a5f2-fa17e9d1a4dd",
"metadata": {
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"email = \"[email protected]\"\n",
"product = \"Naas Enterprise\"\n",
"amount = 100\n",
"currency = 'USD'\n",
"body = {}"
]
},
{
"cell_type": "markdown",
"id": "c708fbdc-74d7-4c5a-bcf4-8672ef7bdbe2",
"metadata": {
"execution": {
"iopub.execute_input": "2023-09-26T17:20:36.759189Z",
"iopub.status.busy": "2023-09-26T17:20:36.758881Z",
"iopub.status.idle": "2023-09-26T17:20:36.765546Z",
"shell.execute_reply": "2023-09-26T17:20:36.764836Z",
"shell.execute_reply.started": "2023-09-26T17:20:36.759155Z"
},
"papermill": {},
"tags": [
"parameters"
]
},
"source": [
"### Setup parameters\n",
"The webhook body will be injected below this cell when the webhook is triggered. \n",
"Therefore, it is important to set up how you will handle the injected variable from the body in order to make your script work.\n",
"To receive the body from the webhook, please ensure that this cell is tagged as \"parameters\"."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cf09c4bb-419b-4b20-9b85-2778dfae0db2",
"metadata": {
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"# Parameters\n",
"if len(body) > 0:\n",
" email = body.get(\"email\")\n",
" product = body.get(\"product\")\n",
" amount = body.get(\"amount\")\n",
" currency = body.get(\"currency\")"
]
},
{
"cell_type": "markdown",
"id": "bf29c888-784f-4427-9a1b-0161fcdd8246",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"## Model"
]
},
{
"cell_type": "markdown",
"id": "090529fe-160d-4099-bfd1-e19fe6356777",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Send text to Idea"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d0bd8c37-7284-471d-beea-b6d19924c2f7",
"metadata": {},
"outputs": [],
"source": [
"status = \"ok\"\n",
"message = f\"❌ Unable to Connect to Stripe. Payment link not sent to: '{email}'\""
]
},
{
"cell_type": "markdown",
"id": "9ef12d0f-2efe-4163-90a9-2ec9206c2ce5",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"## Output"
]
},
{
"cell_type": "markdown",
"id": "a92f90b2-c999-49d4-8f70-64bed955ea61",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Create or update Webhook"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "592a1ba4-cdf6-4119-b222-42b64f62e7c0",
"metadata": {},
"outputs": [],
"source": [
"naas.webhook.add()"
]
},
{
"cell_type": "markdown",
"id": "fbc1a6c1-ad7d-47a5-ab13-2004752cd03f",
"metadata": {
"execution": {
"iopub.execute_input": "2023-09-26T15:15:09.022426Z",
"iopub.status.busy": "2023-09-26T15:15:09.022118Z",
"iopub.status.idle": "2023-09-26T15:15:09.025782Z",
"shell.execute_reply": "2023-09-26T15:15:09.025087Z",
"shell.execute_reply.started": "2023-09-26T15:15:09.022389Z"
},
"papermill": {},
"tags": []
},
"source": [
"### Return JSON response\n",
"Response sent to the browser before displayed in Chat UI."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5609eb79-ccc5-4370-af21-a57eb84f71d4",
"metadata": {
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"naas.webhook.respond_json(\n",
" {\n",
" \"status\": status, \n",
" \"message\": message\n",
" }\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2b106255-4498-491b-9674-45cd1563306f",
"metadata": {},
"outputs": [],
"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
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,18 @@
"source": [
"### Setup variables\n",
"**Inputs**\n",
"- `entity_dir`: This variable represents the entity directory.\n",
"- `entity_name`: This variable holds the entity name.\n",
"- `input_dir`: Input directory to retrieve file from.\n",
"- `entity_dir`: Entity directory.\n",
"- `entity_name`: Entity name.\n",
"- `input_dir`: Path of the directory to retrieve file from.\n",
"- `input_file`: Name of the file to be retrieved.\n",
"- `spreadsheet_url`: Google Sheets spreadsheet URL.\n",
"- `sheet_name`: Google Sheets sheet name.\n",
"- `title`: Graph title.\n",
"- `linkedin_url`: Entity LinkedIn URL used as graph source.\n",
"\n",
"**Outputs**\n",
"- `output_dir`: This variable is used for storing the path to the directory where the output files will be saved."
"- `output_dir`: Path to the directory where the output files will be saved.\n",
"- `output_file`: Output files base name"
]
},
{
Expand All @@ -150,7 +151,8 @@
"linkedin_url = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", \"0\"), \"linkedin_url\")\n",
"\n",
"# Outputs\n",
"output_dir = os.path.join(entity_dir, \"growth-engine\", date.today().isoformat())"
"output_dir = os.path.join(entity_dir, \"growth-engine\", date.today().isoformat())\n",
"output_file = \"growth_trend\""
]
},
{
Expand Down Expand Up @@ -181,9 +183,8 @@
},
"outputs": [],
"source": [
"csv_output = os.path.join(output_dir, \"growth_trend\")\n",
"html_output = os.path.join(output_dir, \"growth_trend.html\")\n",
"image_output = os.path.join(output_dir, \"growth_trend.png\")"
"html_output = os.path.join(output_dir, f\"{output_file}.html\")\n",
"image_output = os.path.join(output_dir, f\"{output_file}.png\")"
]
},
{
Expand Down Expand Up @@ -567,7 +568,7 @@
},
"outputs": [],
"source": [
"pdump(output_dir, df_trend, csv_output)"
"pdump(output_dir, df_trend, output_file)"
]
},
{
Expand Down
Loading

0 comments on commit 831598b

Please sign in to comment.