File size: 3,736 Bytes
cfd3735
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "16763ed3",
   "metadata": {},
   "source": [
    "# IFTTT WebHooks\n",
    "\n",
    "This notebook shows how to use IFTTT Webhooks.\n",
    "\n",
    "From https://github.com/SidU/teams-langchain-js/wiki/Connecting-IFTTT-Services.\n",
    "\n",
    "## Creating a webhook\n",
    "- Go to https://ifttt.com/create\n",
    "\n",
    "## Configuring the \"If This\"\n",
    "- Click on the \"If This\" button in the IFTTT interface.\n",
    "- Search for \"Webhooks\" in the search bar.\n",
    "- Choose the first option for \"Receive a web request with a JSON payload.\"\n",
    "- Choose an Event Name that is specific to the service you plan to connect to.\n",
    "This will make it easier for you to manage the webhook URL.\n",
    "For example, if you're connecting to Spotify, you could use \"Spotify\" as your\n",
    "Event Name.\n",
    "- Click the \"Create Trigger\" button to save your settings and create your webhook.\n",
    "\n",
    "## Configuring the \"Then That\"\n",
    "- Tap on the \"Then That\" button in the IFTTT interface.\n",
    "- Search for the service you want to connect, such as Spotify.\n",
    "- Choose an action from the service, such as \"Add track to a playlist\".\n",
    "- Configure the action by specifying the necessary details, such as the playlist name,\n",
    "e.g., \"Songs from AI\".\n",
    "- Reference the JSON Payload received by the Webhook in your action. For the Spotify\n",
    "scenario, choose \"{{JsonPayload}}\" as your search query.\n",
    "- Tap the \"Create Action\" button to save your action settings.\n",
    "- Once you have finished configuring your action, click the \"Finish\" button to\n",
    "complete the setup.\n",
    "- Congratulations! You have successfully connected the Webhook to the desired\n",
    "service, and you're ready to start receiving data and triggering actions 🎉\n",
    "\n",
    "## Finishing up\n",
    "- To get your webhook URL go to https://ifttt.com/maker_webhooks/settings\n",
    "- Copy the IFTTT key value from there. The URL is of the form\n",
    "https://maker.ifttt.com/use/YOUR_IFTTT_KEY. Grab the YOUR_IFTTT_KEY value.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "10a46e7e",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.tools.ifttt import IFTTTWebhook"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "12003d72",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "key = os.environ[\"IFTTTKey\"]\n",
    "url = f\"https://maker.ifttt.com/trigger/spotify/json/with/key/{key}\"\n",
    "tool = IFTTTWebhook(name=\"Spotify\", description=\"Add a song to spotify playlist\", url=url)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "6e68f846",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"Congratulations! You've fired the spotify JSON event\""
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tool.run(\"taylor swift\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a7e599c9",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}