@bigbinary/neeto-whatsapp-frontend 1.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 +186 -0
- package/app/javascript/src/translations/ar.json +5 -0
- package/app/javascript/src/translations/bg.json +5 -0
- package/app/javascript/src/translations/ca.json +5 -0
- package/app/javascript/src/translations/cs.json +5 -0
- package/app/javascript/src/translations/da.json +5 -0
- package/app/javascript/src/translations/de.json +5 -0
- package/app/javascript/src/translations/en.json +21 -0
- package/app/javascript/src/translations/es-MX.json +5 -0
- package/app/javascript/src/translations/es.json +5 -0
- package/app/javascript/src/translations/et.json +5 -0
- package/app/javascript/src/translations/fi.json +5 -0
- package/app/javascript/src/translations/fil.json +5 -0
- package/app/javascript/src/translations/fr.json +5 -0
- package/app/javascript/src/translations/he.json +5 -0
- package/app/javascript/src/translations/hi.json +5 -0
- package/app/javascript/src/translations/hr.json +5 -0
- package/app/javascript/src/translations/id.json +5 -0
- package/app/javascript/src/translations/index.js +3 -0
- package/app/javascript/src/translations/it.json +5 -0
- package/app/javascript/src/translations/ja.json +5 -0
- package/app/javascript/src/translations/ko.json +5 -0
- package/app/javascript/src/translations/nl.json +5 -0
- package/app/javascript/src/translations/pl.json +5 -0
- package/app/javascript/src/translations/pt-BR.json +5 -0
- package/app/javascript/src/translations/pt.json +5 -0
- package/app/javascript/src/translations/ro.json +5 -0
- package/app/javascript/src/translations/ru.json +5 -0
- package/app/javascript/src/translations/sk.json +5 -0
- package/app/javascript/src/translations/sl.json +5 -0
- package/app/javascript/src/translations/sv.json +5 -0
- package/app/javascript/src/translations/th.json +5 -0
- package/app/javascript/src/translations/tr.json +5 -0
- package/app/javascript/src/translations/uk.json +5 -0
- package/app/javascript/src/translations/vi.json +5 -0
- package/app/javascript/src/translations/zh-CN.json +5 -0
- package/app/javascript/src/translations/zh-TW.json +5 -0
- package/dist/WelcomeScreen.js +13 -0
- package/dist/WelcomeScreen.js.map +1 -0
- package/dist/WhatsAppMessages.js +488 -0
- package/dist/WhatsAppMessages.js.map +1 -0
- package/dist/cjs/WelcomeScreen.js +15 -0
- package/dist/cjs/WelcomeScreen.js.map +1 -0
- package/dist/cjs/WhatsAppMessages.js +490 -0
- package/dist/cjs/WhatsAppMessages.js.map +1 -0
- package/dist/cjs/index.js +31 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/package.json +238 -0
- package/types.d.ts +8 -0
package/README.md
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# neeto-whatsapp-nano
|
|
2
|
+
|
|
3
|
+
The `neeto-whatsapp-nano` manages WhatsApp messaging within neeto applications.
|
|
4
|
+
The nano exports the `@bigbinary/neeto-whatsapp-frontend` NPM package and
|
|
5
|
+
`neeto-whatsapp-engine` Rails engine for development.
|
|
6
|
+
|
|
7
|
+
# Contents
|
|
8
|
+
|
|
9
|
+
1. [Development with Host Application](#development-with-host-application)
|
|
10
|
+
- [Engine](#engine)
|
|
11
|
+
- [Installation](#installation)
|
|
12
|
+
- [Usage](#usage)
|
|
13
|
+
- [Frontend package](#frontend-package)
|
|
14
|
+
- [Installation](#installation-1)
|
|
15
|
+
- [Instructions for development](#instructions-for-development)
|
|
16
|
+
- [Components](#components)
|
|
17
|
+
2. [Instructions for Publishing](#instructions-for-publishing)
|
|
18
|
+
|
|
19
|
+
# Development with Host Application
|
|
20
|
+
|
|
21
|
+
## Engine
|
|
22
|
+
|
|
23
|
+
The engine handles WhatsApp Business API integration, including sending and
|
|
24
|
+
receiving messages, processing webhooks for message status updates, and managing
|
|
25
|
+
WhatsApp message templates.
|
|
26
|
+
|
|
27
|
+
### Installation
|
|
28
|
+
|
|
29
|
+
1. Add this line to your application's Gemfile:
|
|
30
|
+
|
|
31
|
+
```ruby
|
|
32
|
+
source "NEETO_GEM_SERVER_URL" do
|
|
33
|
+
# ..existing gems
|
|
34
|
+
|
|
35
|
+
gem 'neeto-whatsapp-engine'
|
|
36
|
+
|
|
37
|
+
# Use this for live development:
|
|
38
|
+
# gem 'neeto-whatsapp-engine', path: "../neeto-whatsapp-nano"
|
|
39
|
+
end
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
2. And then execute:
|
|
43
|
+
|
|
44
|
+
```shell
|
|
45
|
+
bundle install
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
3. Add this line to your application's `config/routes.rb` file:
|
|
49
|
+
|
|
50
|
+
```ruby
|
|
51
|
+
mount NeetoWhatsappEngine::Engine, at: "/neeto_whatsapp"
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
**NOTE: The mount point must be `/neeto_whatsapp` and cannot be changed to
|
|
55
|
+
any other path.**
|
|
56
|
+
|
|
57
|
+
4. Run the following command to copy the migrations from the engine to the host
|
|
58
|
+
application:
|
|
59
|
+
|
|
60
|
+
```shell
|
|
61
|
+
bundle exec rails neeto_whatsapp_engine:install:migrations
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
5. Add the migrations to the database:
|
|
65
|
+
|
|
66
|
+
```shell
|
|
67
|
+
bundle exec rails db:migrate
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
6. Add the following environment variables:
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
WHATSAPP_NANO_WEBHOOK_VERIFY_TOKEN=abc123
|
|
74
|
+
WHATSAPP_WEBHOOK_APP_SECRET=abc123
|
|
75
|
+
WHATSAPP_ENABLED_ORGANIZATIONS="spinkart"
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
7. Add the following association to the entity to which you want to associate
|
|
79
|
+
the whatsapp messages
|
|
80
|
+
|
|
81
|
+
```ruby
|
|
82
|
+
has_many :whatsapp_messages, class_name: "NeetoWhatsappEngine::Message", as: :entity, dependent: :destroy
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
8. Override the fetch_entity! method for
|
|
86
|
+
NeetoWhatsappEngine::Api::V1::MessagesController
|
|
87
|
+
|
|
88
|
+
```ruby
|
|
89
|
+
# app/overrides/controllers/neeto_whatsapp_engine/api/v1/messages_controller_override.rb
|
|
90
|
+
|
|
91
|
+
# frozen_string_literal: true
|
|
92
|
+
|
|
93
|
+
NeetoWhatsappEngine::Api::V1::MessagesController.class_eval do
|
|
94
|
+
|
|
95
|
+
private
|
|
96
|
+
def fetch_entity!
|
|
97
|
+
# Fetch entity here
|
|
98
|
+
# example:
|
|
99
|
+
# @entity = @organization.bookings.find_by!(id: params[:entity_id])
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
9. The backend exposes 2 services for sending whatsapp messages:
|
|
105
|
+
|
|
106
|
+
- For sending template messages
|
|
107
|
+
|
|
108
|
+
```ruby
|
|
109
|
+
NeetoWhatsappEngine::TemplateMessageService.new(account).process(
|
|
110
|
+
recipient_phone:,
|
|
111
|
+
template_name:,
|
|
112
|
+
language_code:,
|
|
113
|
+
entity: booking,
|
|
114
|
+
template_params: [
|
|
115
|
+
# This is an example on how to send params.
|
|
116
|
+
# Check the params required based on the template(created on meta's dashboard) which you are going to use.
|
|
117
|
+
{ name: "client_name", type: "text", text: booking.name },
|
|
118
|
+
{ name: "meeting_name", type: "text", text: booking.meeting.name },
|
|
119
|
+
{ name: "host_meeting_time", type: "text", text: meeting_time_in_host_time_zone },
|
|
120
|
+
{ name: "attendee_list", type: "text", text: attendee_list },
|
|
121
|
+
{ name: "meeting_location", type: "text", text: meeting_location },
|
|
122
|
+
{ name: "booking_id", type: "text", text: booking.sid }
|
|
123
|
+
]
|
|
124
|
+
)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
- For sending free-form text message, you can use the frontend component
|
|
128
|
+
`WhatsAppMessages` which handles it internally. But if you want to call it
|
|
129
|
+
manually, then
|
|
130
|
+
|
|
131
|
+
```ruby
|
|
132
|
+
NeetoWhatsappEngine::TextMessageService.new(account).process(
|
|
133
|
+
recipient_phone:,
|
|
134
|
+
entity:
|
|
135
|
+
message_text: "Hello",
|
|
136
|
+
)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Frontend package
|
|
140
|
+
|
|
141
|
+
### Installation
|
|
142
|
+
|
|
143
|
+
1. Install the latest `neeto-whatsapp-frontend` package using the below command:
|
|
144
|
+
```shell
|
|
145
|
+
yarn add @bigbinary/neeto-whatsapp-frontend
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Instructions for development
|
|
149
|
+
|
|
150
|
+
Check the
|
|
151
|
+
[Frontend package development guide](https://neeto-engineering.neetokb.com/p/a-d34cb4b0)
|
|
152
|
+
for step-by-step instructions to develop the frontend package.
|
|
153
|
+
|
|
154
|
+
### Components
|
|
155
|
+
|
|
156
|
+
#### `WhatsAppMessages` ([source code](https://github.com/bigbinary/neeto-whatsapp-nano/blob/main/app/javascript/src/components/WhatsAppMessages/index.jsx))
|
|
157
|
+
|
|
158
|
+
This component provides a chat interface for viewing and sending WhatsApp
|
|
159
|
+
messages for a given entity. It displays a scrollable message list with
|
|
160
|
+
WhatsApp-style formatting, status icons, and a sticky compose form at the
|
|
161
|
+
bottom. Messages are polled every 10 seconds for real-time updates.
|
|
162
|
+
|
|
163
|
+
##### Props
|
|
164
|
+
|
|
165
|
+
- `entityId`: The ID of the entity whose messages should be displayed.
|
|
166
|
+
- `entityType`: The type of the entity (e.g., `"Booking"`).
|
|
167
|
+
|
|
168
|
+
##### Usage
|
|
169
|
+
|
|
170
|
+
```jsx
|
|
171
|
+
import React from "react";
|
|
172
|
+
|
|
173
|
+
import { WhatsAppMessages } from "@bigbinary/neeto-whatsapp-frontend";
|
|
174
|
+
|
|
175
|
+
const App = ({ bookingId }) => (
|
|
176
|
+
<WhatsAppMessages entityId={bookingId} entityType="Booking" />
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
export default App;
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
# Instructions for Publishing
|
|
183
|
+
|
|
184
|
+
Consult the
|
|
185
|
+
[building and releasing packages](https://neeto-engineering.neetokb.com/articles/building-and-releasing-packages)
|
|
186
|
+
guide for details on how to publish.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"neetoWhatsapp": {
|
|
3
|
+
"welcomeScreen": "Welcome to neeto whatsapp nano",
|
|
4
|
+
"messages": {
|
|
5
|
+
"emptyState": "There are no messages to show.",
|
|
6
|
+
"status": {
|
|
7
|
+
"pending": "Pending",
|
|
8
|
+
"sent": "Sent",
|
|
9
|
+
"delivered": "Delivered",
|
|
10
|
+
"read": "Read",
|
|
11
|
+
"failed": "Failed"
|
|
12
|
+
},
|
|
13
|
+
"compose": {
|
|
14
|
+
"placeholder": "Type a message...",
|
|
15
|
+
"send": "Send",
|
|
16
|
+
"windowExpired": "You can only send messages within 24 hours of the user's last message. Please wait for the user to reply to continue.",
|
|
17
|
+
"sendError": "Failed to send message. Please try again."
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useTranslation } from 'react-i18next';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
var WelcomeScreen = function WelcomeScreen() {
|
|
5
|
+
var _useTranslation = useTranslation(),
|
|
6
|
+
t = _useTranslation.t;
|
|
7
|
+
return /*#__PURE__*/jsx("div", {
|
|
8
|
+
children: t("neetoWhatsapp.welcomeScreen")
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { WelcomeScreen as default };
|
|
13
|
+
//# sourceMappingURL=WelcomeScreen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WelcomeScreen.js","sources":["../app/javascript/src/components/WelcomeScreen/index.jsx"],"sourcesContent":["import { useTranslation } from \"react-i18next\";\n\nconst WelcomeScreen = () => {\n const { t } = useTranslation();\n\n return <div>{t(\"neetoWhatsapp.welcomeScreen\")}</div>;\n};\nexport default WelcomeScreen;\n"],"names":["WelcomeScreen","_useTranslation","useTranslation","t","_jsx","children"],"mappings":";;;AAEA,IAAMA,aAAa,GAAG,SAAhBA,aAAaA,GAAS;AAC1B,EAAA,IAAAC,eAAA,GAAcC,cAAc,EAAE;IAAtBC,CAAC,GAAAF,eAAA,CAADE,CAAC;AAET,EAAA,oBAAOC,GAAA,CAAA,KAAA,EAAA;IAAAC,QAAA,EAAMF,CAAC,CAAC,6BAA6B;AAAC,GAAM,CAAC;AACtD;;;;"}
|