@contenify/chatbot 4.0.0 → 4.0.1

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.
package/README.md CHANGED
@@ -1,271 +1,138 @@
1
1
  # @contenify/chatbot
2
2
 
3
- AI-powered news chatbot widget for React applications. Embed an intelligent content creation assistant that rewrites news, generates articles, and creates social content directly inside your app.
4
-
5
- ---
3
+ AI-powered news chatbot widget for content creation. Paste a news URL or topic, get a fully rewritten article with SEO analysis, export to PDF/DOCX, or post it directly to your platform.
6
4
 
7
5
  ## Installation
8
6
 
9
7
  ```bash
10
8
  npm install @contenify/chatbot
11
- ```
12
-
13
- ```bash
9
+ # or
14
10
  yarn add @contenify/chatbot
15
11
  ```
16
12
 
17
- ```bash
18
- pnpm add @contenify/chatbot
19
- ```
20
-
21
- > **Peer dependencies:** Requires `react >= 18` and `react-dom >= 18`.
22
-
23
- ---
24
-
25
13
  ## Quick Start
26
14
 
27
- ### 1. Import the component and styles
28
-
29
15
  ```tsx
30
16
  import { ContenifyChatBot } from '@contenify/chatbot'
31
17
  import '@contenify/chatbot/styles.css'
32
- ```
33
-
34
- ### 2. Add the chatbot to your app
35
18
 
36
- ```tsx
37
19
  export default function App() {
38
20
  return (
39
21
  <ContenifyChatBot
40
- apiUrl="https://your-api.example.com/api"
41
- apiKey="YOUR_API_KEY"
22
+ apiUrl="https://your-backend.com/api"
23
+ apiKey="your-api-key"
42
24
  />
43
25
  )
44
26
  }
45
27
  ```
46
28
 
47
- That's it. The chatbot renders a full-featured AI news assistant with trending news, article rewriting, and content creation built in.
48
-
49
- ---
50
-
51
29
  ## Props
52
30
 
53
31
  | Prop | Type | Required | Description |
54
32
  |------|------|----------|-------------|
55
- | `apiUrl` | `string` | Yes | Base URL of your Contenify backend API (e.g. `https://api.example.com/api`) |
56
- | `apiKey` | `string` | Yes | Your licence API key |
57
- | `domain` | `string` | No | Domain identifier for multi-tenant setups |
58
- | `onPost` | `(content: string, keywords: string[]) => void` | No | Callback fired when the user clicks **Post** on a generated article. Receives the HTML content and meta keywords. |
33
+ | `apiUrl` | `string` | No | Base URL of your Contenify backend API. Defaults to `NEXT_PUBLIC_CONTENIFY_API_URL` env var. |
34
+ | `apiKey` | `string` | No | Your subscription API key. Defaults to `NEXT_PUBLIC_API_KEY` env var. |
35
+ | `domain` | `string` | No | Your site domain, used for source filtering. |
36
+ | `onPost` | `(article: string, keywords: string[]) => void` | No | Called when the user clicks **Post** in the editor. Receives the article HTML and meta keywords. |
37
+
38
+ ## Environment Variables (alternative to props)
39
+
40
+ ```env
41
+ NEXT_PUBLIC_CONTENIFY_API_URL=https://your-backend.com/api
42
+ NEXT_PUBLIC_API_KEY=your-api-key
43
+ NEXT_PUBLIC_CONTENIFY_DOMAIN=yourdomain.com
44
+ ```
59
45
 
60
- ---
46
+ Props take precedence over env vars at runtime.
61
47
 
62
- ## Usage Examples
48
+ ## Styles
63
49
 
64
- ### Basic embed
50
+ Import the stylesheet once at the root of your app:
65
51
 
66
52
  ```tsx
67
- import { ContenifyChatBot } from '@contenify/chatbot'
68
53
  import '@contenify/chatbot/styles.css'
69
-
70
- export default function Page() {
71
- return (
72
- <div style={{ height: '100vh' }}>
73
- <ContenifyChatBot
74
- apiUrl="https://api.example.com/api"
75
- apiKey="LIC-XXXXXX-XXXXXX"
76
- />
77
- </div>
78
- )
79
- }
80
54
  ```
81
55
 
82
- ### With `onPost` callback
56
+ ## Post Button / External Trigger
83
57
 
84
- Handle articles when the user clicks **Post** publish to your CMS, save to a database, or trigger any workflow:
58
+ When the user clicks **Post** inside the article editor, a `contenify-post-article` DOM event fires on `window`. You can listen to it anywhere in your app useful if you need to send data to your own CMS or API independently of the `onPost` prop.
85
59
 
86
- ```tsx
87
- import { ContenifyChatBot } from '@contenify/chatbot'
88
- import '@contenify/chatbot/styles.css'
60
+ ```ts
61
+ window.addEventListener('contenify-post-article', (e: Event) => {
62
+ const { title, subtitle, article, metaDescription, slug, keywords, featuredImage } = (e as CustomEvent).detail
89
63
 
90
- export default function Page() {
91
- const handlePost = (content: string, keywords: string[]) => {
92
- // content is an HTML string, keywords is string[]
93
- console.log('Article HTML:', content)
94
- console.log('Keywords:', keywords)
64
+ // Send to your CMS, API, or publishing pipeline
65
+ await myApi.publish({ title, article, keywords })
66
+ })
67
+ ```
95
68
 
96
- // Example: POST to your CMS
97
- fetch('/api/articles', {
98
- method: 'POST',
99
- headers: { 'Content-Type': 'application/json' },
100
- body: JSON.stringify({ content, keywords }),
101
- })
102
- }
69
+ ### Full payload shape
103
70
 
104
- return (
105
- <ContenifyChatBot
106
- apiUrl="https://api.example.com/api"
107
- apiKey="LIC-XXXXXX-XXXXXX"
108
- onPost={handlePost}
109
- />
110
- )
71
+ ```ts
72
+ {
73
+ title: string
74
+ subtitle: string
75
+ article: string // Rich HTML content
76
+ metaDescription: string
77
+ slug: string // Auto-generated from title, user-editable
78
+ keywords: string[] // Meta keywords array
79
+ featuredImage?: string // URL of featured image (if present)
111
80
  }
112
81
  ```
113
82
 
114
- ### Next.js App Router
115
-
116
- Because the chatbot uses client-side hooks, wrap it in a client component:
117
-
118
- ```tsx
119
- // components/ChatbotWrapper.tsx
120
- 'use client'
83
+ > SEO analysis data is **not** included in the post payload — it is for display only.
121
84
 
122
- import { ContenifyChatBot } from '@contenify/chatbot'
123
- import '@contenify/chatbot/styles.css'
85
+ ## Invalid / Expired API Key
124
86
 
125
- export default function ChatbotWrapper() {
126
- return (
127
- <ContenifyChatBot
128
- apiUrl={process.env.NEXT_PUBLIC_API_URL!}
129
- apiKey={process.env.NEXT_PUBLIC_API_KEY!}
130
- onPost={(content, keywords) => {
131
- console.log('Post triggered', { content, keywords })
132
- }}
133
- />
134
- )
135
- }
136
- ```
87
+ If the API key is missing or rejected, a modal automatically prompts the user to enter a valid key. You can also update the key programmatically at any time:
137
88
 
138
- ```tsx
139
- // app/layout.tsx (or app/page.tsx)
140
- import ChatbotWrapper from '@/components/ChatbotWrapper'
89
+ ```ts
90
+ import { setConfig } from '@contenify/chatbot'
141
91
 
142
- export default function Layout({ children }: { children: React.ReactNode }) {
143
- return (
144
- <html>
145
- <body>
146
- {children}
147
- <ChatbotWrapper />
148
- </body>
149
- </html>
150
- )
151
- }
92
+ setConfig({ apiKey: 'new-api-key' })
152
93
  ```
153
94
 
154
- ### Using `setConfig` (configure once at startup)
95
+ ## Next.js Setup
155
96
 
156
- If you prefer to configure the package once at app startup instead of passing props each time:
97
+ The component uses `"use client"` internally. If your project uses the App Router, wrap it in a client component:
157
98
 
158
99
  ```tsx
159
- // app/providers.tsx (or _app.tsx)
100
+ // app/ChatPage.tsx
160
101
  'use client'
161
-
162
- import { setConfig, ContenifyChatBot } from '@contenify/chatbot'
102
+ import { ContenifyChatBot } from '@contenify/chatbot'
163
103
  import '@contenify/chatbot/styles.css'
164
104
 
165
- setConfig({
166
- apiUrl: 'https://api.example.com/api',
167
- apiKey: 'LIC-XXXXXX-XXXXXX',
168
- domain: 'my-site',
169
- })
170
-
171
- export default function ChatProvider() {
172
- return <ContenifyChatBot />
105
+ export default function ChatPage() {
106
+ return <ContenifyChatBot apiUrl="..." apiKey="..." />
173
107
  }
174
108
  ```
175
109
 
176
- ---
177
-
178
- ## Features
110
+ ## Usage with onPost
179
111
 
180
- | Feature | Description |
181
- |---------|-------------|
182
- | **AI Article Rewriting** | Paste or type a news story — the AI rewrites it in your preferred tone, style, and language |
183
- | **Trending News Panel** | Browse and recreate trending news articles from multiple sources |
184
- | **Multi-language Support** | Generate content in English, Hindi, and more via preferences |
185
- | **Edit Before Posting** | Built-in rich text editor with separate Title, Subtitle, Slug, Meta Description, and Keywords fields |
186
- | **Streaming Output** | Articles stream token-by-token for a fast, real-time writing experience |
187
- | **URL Analysis** | Paste any article URL — the chatbot scrapes and offers actions: recreate, summarise, create social posts, newsletter, blog post, and more |
188
- | **Preferences** | Tone, style, word count, target audience, include quotes/FAQ — all configurable per user |
189
-
190
- ---
191
-
192
- ## TypeScript
193
-
194
- All props and types are exported:
195
-
196
- ```ts
197
- import type {
198
- ContenifyChatBotProps,
199
- Preferences,
200
- ChatbotPreferences,
201
- LocalizationPreferences,
202
- AppearancePreferences,
203
- ContentPreferences,
204
- ContentOption,
205
- AnalyzeInputResponse,
206
- CreateContentPayload,
207
- RecreateSettings,
208
- } from '@contenify/chatbot'
209
- ```
210
-
211
- ### Key types
212
-
213
- ```ts
214
- interface ContenifyChatBotProps {
215
- apiUrl?: string
216
- apiKey?: string
217
- domain?: string
218
- onPost?: (content: string, keywords: string[]) => void
219
- }
220
-
221
- interface ContentPreferences {
222
- tone: 'formal' | 'casual' | 'engaging' | 'professional'
223
- style: 'news' | 'blog' | 'editorial' | 'summary'
224
- wordCount: 'short' | 'medium' | 'long'
225
- includeQuotes: boolean
226
- includeFAQ: boolean
227
- targetAudience: string
228
- }
112
+ ```tsx
113
+ 'use client'
114
+ import { ContenifyChatBot } from '@contenify/chatbot'
115
+ import '@contenify/chatbot/styles.css'
229
116
 
230
- interface LocalizationPreferences {
231
- country: string
232
- state: string
233
- cities: string[]
234
- language: string // e.g. 'en', 'hi'
235
- locale: string
236
- timezone: string
237
- }
117
+ export default function Editor() {
118
+ const handlePost = async (article: string, keywords: string[]) => {
119
+ await fetch('/api/publish', {
120
+ method: 'POST',
121
+ headers: { 'Content-Type': 'application/json' },
122
+ body: JSON.stringify({ article, keywords }),
123
+ })
124
+ }
238
125
 
239
- interface ChatbotPreferences {
240
- name: string
241
- logoUrl?: string
242
- primaryColor: string // hex, e.g. '#6366f1'
243
- secondaryColor: string
244
- theme: 'light' | 'dark' | 'system'
126
+ return (
127
+ <ContenifyChatBot
128
+ apiUrl={process.env.NEXT_PUBLIC_CONTENIFY_API_URL}
129
+ apiKey={process.env.NEXT_PUBLIC_API_KEY}
130
+ onPost={handlePost}
131
+ />
132
+ )
245
133
  }
246
134
  ```
247
135
 
248
- ---
249
-
250
- ## Environment Variables
251
-
252
- When running the development app locally, create a `.env.local` file:
253
-
254
- ```env
255
- NEXT_PUBLIC_CONTENIFY_API_URL=http://localhost:8080/api
256
- NEXT_PUBLIC_API_KEY=YOUR_API_KEY
257
- NEXT_PUBLIC_DOMAIN=
258
- ```
259
-
260
- ---
261
-
262
- ## Requirements
263
-
264
- - React 18+
265
- - A running Contenify backend with a valid API key
266
-
267
- ---
268
-
269
136
  ## License
270
137
 
271
138
  MIT
package/dist/index.js CHANGED
@@ -2901,6 +2901,16 @@ function ContenifyChatBot({ apiUrl, apiKey, domain, onPost }) {
2901
2901
  (0, import_react10.useEffect)(() => {
2902
2902
  setConfig({ apiUrl, apiKey, domain });
2903
2903
  }, [apiUrl, apiKey, domain]);
2904
+ (0, import_react10.useEffect)(() => {
2905
+ if (!onPost) return;
2906
+ const handler = (e) => {
2907
+ var _a, _b;
2908
+ const detail = e.detail;
2909
+ onPost((_a = detail.article) != null ? _a : "", (_b = detail.keywords) != null ? _b : []);
2910
+ };
2911
+ window.addEventListener("contenify-post-article", handler);
2912
+ return () => window.removeEventListener("contenify-post-article", handler);
2913
+ }, [onPost]);
2904
2914
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ChatBot, {});
2905
2915
  }
2906
2916
  var index_default = ContenifyChatBot;