fluidtalk 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
fluidtalk/__init__.py
ADDED
fluidtalk/client.py
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"""FluidTalk Handshake API — official Python client.
|
|
2
|
+
|
|
3
|
+
You own your chatbot's orchestration (when to open a chat, when to follow up, ...);
|
|
4
|
+
this client turns FluidTalk's persona/engine into one method call so you don't have to
|
|
5
|
+
rebuild the HTTP/auth/multipart layer.
|
|
6
|
+
|
|
7
|
+
A conversation can start four ways (builder name -> method):
|
|
8
|
+
Inbound Chat (the lead messages first) -> inbound_chat()
|
|
9
|
+
AI Opener (your persona messages first) -> ai_opener()
|
|
10
|
+
Event Trigger (a platform event fires) -> event_trigger()
|
|
11
|
+
Follow-up (re-engage a quiet lead) -> follow_up()
|
|
12
|
+
Plus upload_image() to host a local image and get a URL for visual context.
|
|
13
|
+
|
|
14
|
+
A conversation is keyed by (persona, target): reuse the same ``target`` for the same
|
|
15
|
+
lead and the engine keeps phase/state across turns. The persona+engine are fixed by your key.
|
|
16
|
+
"""
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import json
|
|
20
|
+
import os
|
|
21
|
+
from dataclasses import dataclass, field
|
|
22
|
+
from typing import Any, Dict, List, Optional
|
|
23
|
+
|
|
24
|
+
import requests
|
|
25
|
+
|
|
26
|
+
DEFAULT_BASE_URL = "https://api-talk.fluidvip.com"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class FluidTalkError(Exception):
|
|
30
|
+
"""Raised on a non-2xx response. ``status`` is the HTTP code, ``detail`` the parsed body."""
|
|
31
|
+
|
|
32
|
+
def __init__(self, status: int, detail: Any, message: str):
|
|
33
|
+
super().__init__(message)
|
|
34
|
+
self.status = status
|
|
35
|
+
self.detail = detail
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@dataclass
|
|
39
|
+
class ChatResult:
|
|
40
|
+
reply: str
|
|
41
|
+
replies: List[str]
|
|
42
|
+
should_send_photo: bool
|
|
43
|
+
photo_url: Optional[str]
|
|
44
|
+
session_id: str
|
|
45
|
+
ignored: bool
|
|
46
|
+
ignore_reason: Optional[str]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@dataclass
|
|
50
|
+
class ActionResult:
|
|
51
|
+
session_id: str
|
|
52
|
+
message: str
|
|
53
|
+
ignored: bool
|
|
54
|
+
ignore_reason: Optional[str]
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@dataclass
|
|
58
|
+
class UploadResult:
|
|
59
|
+
url: str
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class FluidTalk:
|
|
63
|
+
def __init__(
|
|
64
|
+
self,
|
|
65
|
+
api_key: str,
|
|
66
|
+
base_url: str = DEFAULT_BASE_URL,
|
|
67
|
+
own_username: Optional[str] = None,
|
|
68
|
+
timeout: float = 60.0,
|
|
69
|
+
):
|
|
70
|
+
if not api_key:
|
|
71
|
+
raise ValueError("FluidTalk: api_key is required.")
|
|
72
|
+
self.api_key = api_key
|
|
73
|
+
self.base_url = base_url.rstrip("/")
|
|
74
|
+
self.own_username = own_username
|
|
75
|
+
self.timeout = timeout
|
|
76
|
+
|
|
77
|
+
def inbound_chat(
|
|
78
|
+
self,
|
|
79
|
+
target: str,
|
|
80
|
+
message: str,
|
|
81
|
+
own_username: Optional[str] = None,
|
|
82
|
+
image_url: Optional[str] = None,
|
|
83
|
+
image_path: Optional[str] = None,
|
|
84
|
+
) -> ChatResult:
|
|
85
|
+
"""Inbound Chat — the lead messaged first (or continue an ongoing conversation). POST /chat."""
|
|
86
|
+
body = self._post(
|
|
87
|
+
"/api/v1/bot/chat",
|
|
88
|
+
{
|
|
89
|
+
"target": target,
|
|
90
|
+
"message": message,
|
|
91
|
+
"own_username": own_username or self.own_username,
|
|
92
|
+
"image_url": image_url,
|
|
93
|
+
},
|
|
94
|
+
image_path=image_path,
|
|
95
|
+
)
|
|
96
|
+
return ChatResult(
|
|
97
|
+
reply=body.get("reply", ""),
|
|
98
|
+
replies=body.get("replies", []),
|
|
99
|
+
should_send_photo=bool(body.get("should_send_photo")),
|
|
100
|
+
photo_url=body.get("photo_url"),
|
|
101
|
+
session_id=body.get("session_id"),
|
|
102
|
+
ignored=bool(body.get("ignored")),
|
|
103
|
+
ignore_reason=body.get("ignore_reason"),
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
def ai_opener(
|
|
107
|
+
self,
|
|
108
|
+
target: str,
|
|
109
|
+
own_username: Optional[str] = None,
|
|
110
|
+
image_url: Optional[str] = None,
|
|
111
|
+
image_path: Optional[str] = None,
|
|
112
|
+
) -> ActionResult:
|
|
113
|
+
"""AI Opener — your persona sends the first message to a new lead. action=OUTREACH."""
|
|
114
|
+
return self._action(
|
|
115
|
+
{"target": target, "action": "OUTREACH", "own_username": own_username or self.own_username, "image_url": image_url},
|
|
116
|
+
image_path,
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
def event_trigger(
|
|
120
|
+
self,
|
|
121
|
+
target: str,
|
|
122
|
+
event_type: str,
|
|
123
|
+
context: Optional[Dict[str, Any]] = None,
|
|
124
|
+
own_username: Optional[str] = None,
|
|
125
|
+
image_url: Optional[str] = None,
|
|
126
|
+
image_path: Optional[str] = None,
|
|
127
|
+
) -> ActionResult:
|
|
128
|
+
"""Event Trigger — a platform event fires; ``event_type`` must match an Event Trigger
|
|
129
|
+
node's event id in the engine. action=ENTRY_POINT."""
|
|
130
|
+
return self._action(
|
|
131
|
+
{
|
|
132
|
+
"target": target,
|
|
133
|
+
"action": "ENTRY_POINT",
|
|
134
|
+
"entry_type": event_type,
|
|
135
|
+
"entry_context": json.dumps(context) if context else None,
|
|
136
|
+
"own_username": own_username or self.own_username,
|
|
137
|
+
"image_url": image_url,
|
|
138
|
+
},
|
|
139
|
+
image_path,
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
def follow_up(self, target: str, own_username: Optional[str] = None) -> ActionResult:
|
|
143
|
+
"""Follow-up — re-engage a lead who went quiet (conversation must already exist). action=FOLLOW_UP."""
|
|
144
|
+
return self._action(
|
|
145
|
+
{"target": target, "action": "FOLLOW_UP", "own_username": own_username or self.own_username},
|
|
146
|
+
None,
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
def upload_image(
|
|
150
|
+
self,
|
|
151
|
+
path: Optional[str] = None,
|
|
152
|
+
data: Optional[bytes] = None,
|
|
153
|
+
filename: Optional[str] = None,
|
|
154
|
+
) -> UploadResult:
|
|
155
|
+
"""Upload a local image (or bytes) and get a hosted URL for visual context. POST /upload."""
|
|
156
|
+
if path and data is None:
|
|
157
|
+
with open(path, "rb") as f:
|
|
158
|
+
data = f.read()
|
|
159
|
+
filename = filename or os.path.basename(path)
|
|
160
|
+
if data is None:
|
|
161
|
+
raise ValueError("upload_image: provide path= or data= (with filename=).")
|
|
162
|
+
body = self._post("/api/v1/bot/upload", {}, file=(filename or "image.jpg", data))
|
|
163
|
+
return UploadResult(url=body.get("url"))
|
|
164
|
+
|
|
165
|
+
# --- internals ---
|
|
166
|
+
def _action(self, fields: Dict[str, Optional[str]], image_path: Optional[str]) -> ActionResult:
|
|
167
|
+
body = self._post("/api/v1/bot/action", fields, image_path=image_path)
|
|
168
|
+
return ActionResult(
|
|
169
|
+
session_id=body.get("session_id"),
|
|
170
|
+
message=body.get("message", ""),
|
|
171
|
+
ignored=bool(body.get("ignored")),
|
|
172
|
+
ignore_reason=body.get("ignore_reason"),
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
def _post(
|
|
176
|
+
self,
|
|
177
|
+
path: str,
|
|
178
|
+
fields: Dict[str, Optional[str]],
|
|
179
|
+
image_path: Optional[str] = None,
|
|
180
|
+
file: Optional[tuple] = None,
|
|
181
|
+
) -> Dict[str, Any]:
|
|
182
|
+
data = {k: v for k, v in fields.items() if v is not None and v != ""}
|
|
183
|
+
files = None
|
|
184
|
+
if file is not None:
|
|
185
|
+
files = {"file": file}
|
|
186
|
+
elif image_path:
|
|
187
|
+
with open(image_path, "rb") as f:
|
|
188
|
+
files = {"file": (os.path.basename(image_path), f.read())}
|
|
189
|
+
try:
|
|
190
|
+
res = requests.post(
|
|
191
|
+
self.base_url + path,
|
|
192
|
+
headers={"X-API-Key": self.api_key},
|
|
193
|
+
data=data,
|
|
194
|
+
files=files,
|
|
195
|
+
timeout=self.timeout,
|
|
196
|
+
)
|
|
197
|
+
except requests.RequestException as e:
|
|
198
|
+
raise FluidTalkError(0, {"error": "network_error"}, f"Network error reaching FluidTalk: {e}")
|
|
199
|
+
try:
|
|
200
|
+
body = res.json()
|
|
201
|
+
except ValueError:
|
|
202
|
+
body = {"detail": res.text}
|
|
203
|
+
if not res.ok:
|
|
204
|
+
detail = body.get("detail") if isinstance(body, dict) else body
|
|
205
|
+
raise FluidTalkError(res.status_code, body, f"FluidTalk {res.status_code}: {detail}")
|
|
206
|
+
return body
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fluidtalk
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Official Python client for the FluidTalk Handshake API — drop FluidTalk AI persona replies into your own chatbot backend.
|
|
5
|
+
Author: FluidTalk
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://talk.fluidvip.com
|
|
8
|
+
Keywords: fluidtalk,chatbot,ai,handshake,sdk
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Topic :: Communications :: Chat
|
|
13
|
+
Requires-Python: >=3.8
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: requests>=2.25
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# fluidtalk (Python)
|
|
20
|
+
|
|
21
|
+
Official Python client for the **FluidTalk Handshake API**. Drop FluidTalk's AI persona replies into your own chatbot backend without rebuilding the HTTP/auth/multipart layer.
|
|
22
|
+
|
|
23
|
+
You keep your own orchestration (when to open a chat, when to follow up, where to send messages); this client just gives you the persona's reply in one call.
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install fluidtalk
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from fluidtalk import FluidTalk, FluidTalkError
|
|
31
|
+
|
|
32
|
+
ft = FluidTalk(
|
|
33
|
+
api_key="ft_sk_...", # scoped to one persona + engine
|
|
34
|
+
own_username="@my_account", # optional default for tracking / dedup
|
|
35
|
+
# base_url="https://api-talk.fluidvip.com" (default)
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
# A lead messaged you -> get the persona's reply and relay it on your platform
|
|
39
|
+
res = ft.inbound_chat(target="@john_doe", message="hey, saw your post!")
|
|
40
|
+
for bubble in res.replies:
|
|
41
|
+
my_chat.send("@john_doe", bubble)
|
|
42
|
+
if res.should_send_photo and res.photo_url:
|
|
43
|
+
my_chat.send_image("@john_doe", res.photo_url)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Concepts → methods
|
|
47
|
+
|
|
48
|
+
A conversation can start four ways. The builder names map to these methods (the API wire value is handled for you):
|
|
49
|
+
|
|
50
|
+
| Builder name | When | Method |
|
|
51
|
+
| :-- | :-- | :-- |
|
|
52
|
+
| **Inbound Chat** | the lead messages first (or an ongoing chat) | `ft.inbound_chat(target, message)` |
|
|
53
|
+
| **AI Opener** | your persona messages first | `ft.ai_opener(target)` |
|
|
54
|
+
| **Event Trigger** | a platform event fires | `ft.event_trigger(target, event_type, context)` |
|
|
55
|
+
| **Follow-up** | re-engage a quiet lead | `ft.follow_up(target)` |
|
|
56
|
+
| — | host a local image for context | `ft.upload_image(path=...)` |
|
|
57
|
+
|
|
58
|
+
A conversation is keyed by **(persona, `target`)** — reuse the same `target` for the same lead and the engine keeps phase/state across turns.
|
|
59
|
+
|
|
60
|
+
## Examples
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
# AI opener (optionally with a profile screenshot for better targeting)
|
|
64
|
+
opener = ft.ai_opener(target="@lead", image_path="./profile.jpg")
|
|
65
|
+
my_chat.send("@lead", opener.message)
|
|
66
|
+
|
|
67
|
+
# Platform event (event_type must match an Event Trigger configured in your engine)
|
|
68
|
+
ev = ft.event_trigger(target="@lead", event_type="story_reaction", context={"reaction": "🔥"})
|
|
69
|
+
|
|
70
|
+
# Re-engage a ghost (needs an existing conversation)
|
|
71
|
+
fu = ft.follow_up(target="@lead")
|
|
72
|
+
|
|
73
|
+
# Attach an image the lead sent
|
|
74
|
+
url = ft.upload_image(path="./incoming.jpg").url
|
|
75
|
+
r = ft.inbound_chat(target="@lead", message="what do you think?", image_url=url)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Results: `inbound_chat` → `ChatResult(reply, replies, should_send_photo, photo_url, session_id, ignored, ignore_reason)`; `ai_opener`/`event_trigger`/`follow_up` → `ActionResult(session_id, message, ignored, ignore_reason)`; `upload_image` → `UploadResult(url)`. Send `replies` as separate bubbles; when `should_send_photo`, also send `photo_url`.
|
|
79
|
+
|
|
80
|
+
## Behaviour to handle
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
try:
|
|
84
|
+
res = ft.inbound_chat(target="@lead", message="hi")
|
|
85
|
+
if res.ignored:
|
|
86
|
+
return # duplicate lead, already owned by another account — send nothing
|
|
87
|
+
for bubble in res.replies:
|
|
88
|
+
my_chat.send("@lead", bubble)
|
|
89
|
+
except FluidTalkError as e:
|
|
90
|
+
if e.status == 402: # out of tokens (insufficient_tokens)
|
|
91
|
+
...
|
|
92
|
+
elif e.status == 400: # conversation already DONE / sealed -> stop messaging
|
|
93
|
+
...
|
|
94
|
+
elif e.status == 404: # no conversation yet (follow_up before any contact)
|
|
95
|
+
...
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
- **One token per conversation** — starting a new conversation costs one token; out of tokens → `FluidTalkError(status=402)`.
|
|
99
|
+
- **Sealed conversation** — when finished, the next `inbound_chat` raises `FluidTalkError(status=400)` ("This session is DONE").
|
|
100
|
+
|
|
101
|
+
API keys are **action-only**: send messages and upload images, never change personas/engines/billing (that stays in the dashboard). Keep your `ft_sk_` key secret.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
fluidtalk/__init__.py,sha256=pIcttJTuB-AbdMO08dO0Uab7m_VPn7M7KJE3GRb9_Ow,245
|
|
2
|
+
fluidtalk/client.py,sha256=8IqXrFHLngR2Uqcltnq0NMHI7mqBbEPXoqy2bFCYso8,7221
|
|
3
|
+
fluidtalk-1.0.0.dist-info/licenses/LICENSE,sha256=NvvvC0l_fBzu9YB-5cho2Pz_n9kAZfivp3h3MQEhyC4,1066
|
|
4
|
+
fluidtalk-1.0.0.dist-info/METADATA,sha256=Z7JSbUUeq-xcOqE2jsFbG5rZx9hnbKMpv2ecViEkBLg,4461
|
|
5
|
+
fluidtalk-1.0.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
6
|
+
fluidtalk-1.0.0.dist-info/top_level.txt,sha256=utS1x8HPJKj2Q3_Yj0kj3-Yxl8QiYH5RqeSkq5GoCtA,10
|
|
7
|
+
fluidtalk-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 FluidTalk
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
fluidtalk
|