piece-infobip-whatsapp 0.1.0
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/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const { createPiece, PieceAuth } = require('@activepieces/pieces-framework');
|
|
2
|
+
const { sendWhatsAppText } = require('./lib/actions/send-text');
|
|
3
|
+
const { sendConsentButtons } = require('./lib/actions/send-consent-buttons');
|
|
4
|
+
const { assignToAgent } = require('./lib/actions/assign-to-agent');
|
|
5
|
+
|
|
6
|
+
const infobipAuth = PieceAuth.CustomAuth({
|
|
7
|
+
description: 'Infobip Zugangsdaten',
|
|
8
|
+
props: {
|
|
9
|
+
apiKey: PieceAuth.SecretText({ displayName: 'API Key', required: true }),
|
|
10
|
+
baseUrl: PieceAuth.SecretText({ displayName: 'Base URL', required: true }),
|
|
11
|
+
senderNumber: PieceAuth.SecretText({ displayName: 'Sender-Nummer', required: true }),
|
|
12
|
+
},
|
|
13
|
+
required: true,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const infobipWhatsApp = createPiece({
|
|
17
|
+
displayName: 'Infobip WhatsApp',
|
|
18
|
+
auth: infobipAuth,
|
|
19
|
+
minimumSupportedRelease: '0.20.0',
|
|
20
|
+
logoUrl: 'https://www.infobip.com/favicon.ico',
|
|
21
|
+
authors: ['bauernfeind'],
|
|
22
|
+
actions: [sendWhatsAppText, sendConsentButtons, assignToAgent],
|
|
23
|
+
triggers: [],
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
module.exports = { infobipWhatsApp, infobipAuth };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const { createAction, Property } = require('@activepieces/pieces-framework');
|
|
2
|
+
const { httpClient, HttpMethod } = require('@activepieces/pieces-common');
|
|
3
|
+
const { infobipAuth } = require('../../index');
|
|
4
|
+
|
|
5
|
+
const assignToAgent = createAction({
|
|
6
|
+
name: 'assign_to_agent',
|
|
7
|
+
displayName: 'An Agent zuweisen',
|
|
8
|
+
description: 'Weist eine Conversation einem Agenten oder einer Queue zu',
|
|
9
|
+
auth: infobipAuth,
|
|
10
|
+
props: {
|
|
11
|
+
conversationId: Property.ShortText({ displayName: 'Conversation ID', required: true }),
|
|
12
|
+
assignmentType: Property.StaticDropdown({ displayName: 'Zuweisen an', required: true, options: { options: [{ label: 'Agent', value: 'AGENT' }, { label: 'Queue', value: 'QUEUE' }] } }),
|
|
13
|
+
targetId: Property.ShortText({ displayName: 'Agent-ID oder Queue-ID', required: true }),
|
|
14
|
+
},
|
|
15
|
+
async run(context) {
|
|
16
|
+
const { apiKey, baseUrl } = context.auth;
|
|
17
|
+
const { conversationId, assignmentType, targetId } = context.propsValue;
|
|
18
|
+
const body = assignmentType === 'AGENT' ? { agentId: targetId } : { queueId: targetId };
|
|
19
|
+
const response = await httpClient.sendRequest({
|
|
20
|
+
method: HttpMethod.PUT,
|
|
21
|
+
url: `${baseUrl}/ccaas/1/conversations/${conversationId}`,
|
|
22
|
+
headers: { Authorization: `App ${apiKey}`, 'Content-Type': 'application/json' },
|
|
23
|
+
body,
|
|
24
|
+
});
|
|
25
|
+
return response.body;
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
module.exports = { assignToAgent };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const { createAction, Property } = require('@activepieces/pieces-framework');
|
|
2
|
+
const { httpClient, HttpMethod } = require('@activepieces/pieces-common');
|
|
3
|
+
const { infobipAuth } = require('../../index');
|
|
4
|
+
|
|
5
|
+
const sendConsentButtons = createAction({
|
|
6
|
+
name: 'send_consent_buttons',
|
|
7
|
+
displayName: 'Consent-Buttons senden',
|
|
8
|
+
description: 'Sendet Ja/Nein-Buttons für Consent-Abfrage',
|
|
9
|
+
auth: infobipAuth,
|
|
10
|
+
props: {
|
|
11
|
+
conversationId: Property.ShortText({ displayName: 'Conversation ID', required: true }),
|
|
12
|
+
to: Property.ShortText({ displayName: 'Empfänger-Nummer', required: true }),
|
|
13
|
+
messageText: Property.LongText({ displayName: 'Nachrichtentext', required: true, defaultValue: 'Darf ich Ihnen zukünftig Informationen per WhatsApp zusenden?' }),
|
|
14
|
+
yesLabel: Property.ShortText({ displayName: 'Ja-Button', required: true, defaultValue: 'Ja, ich stimme zu' }),
|
|
15
|
+
noLabel: Property.ShortText({ displayName: 'Nein-Button', required: true, defaultValue: 'Nein, danke' }),
|
|
16
|
+
},
|
|
17
|
+
async run(context) {
|
|
18
|
+
const { apiKey, baseUrl, senderNumber } = context.auth;
|
|
19
|
+
const { to, messageText, yesLabel, noLabel, conversationId } = context.propsValue;
|
|
20
|
+
const response = await httpClient.sendRequest({
|
|
21
|
+
method: HttpMethod.POST,
|
|
22
|
+
url: `${baseUrl}/ccaas/1/conversations/${conversationId}/messages`,
|
|
23
|
+
headers: { Authorization: `App ${apiKey}`, 'Content-Type': 'application/json' },
|
|
24
|
+
body: {
|
|
25
|
+
from: senderNumber, to, channel: 'WHATSAPP', contentType: 'INTERACTIVE',
|
|
26
|
+
content: { interactive: { body: { text: messageText }, action: { buttons: [{ id: 'opt_in', title: yesLabel, type: 'BUTTON' }, { id: 'opt_out', title: noLabel, type: 'BUTTON' }] }, type: 'BUTTON' } },
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
return response.body;
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
module.exports = { sendConsentButtons };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const { createAction, Property } = require('@activepieces/pieces-framework');
|
|
2
|
+
const { httpClient, HttpMethod } = require('@activepieces/pieces-common');
|
|
3
|
+
const { infobipAuth } = require('../../index');
|
|
4
|
+
|
|
5
|
+
const sendWhatsAppText = createAction({
|
|
6
|
+
name: 'send_whatsapp_text',
|
|
7
|
+
displayName: 'WhatsApp Text senden',
|
|
8
|
+
description: 'Sendet eine Textnachricht in eine bestehende Conversation',
|
|
9
|
+
auth: infobipAuth,
|
|
10
|
+
props: {
|
|
11
|
+
conversationId: Property.ShortText({ displayName: 'Conversation ID', required: true }),
|
|
12
|
+
to: Property.ShortText({ displayName: 'Empfänger-Nummer', required: true }),
|
|
13
|
+
message: Property.LongText({ displayName: 'Nachricht', required: true }),
|
|
14
|
+
},
|
|
15
|
+
async run(context) {
|
|
16
|
+
const { apiKey, baseUrl, senderNumber } = context.auth;
|
|
17
|
+
const { to, message, conversationId } = context.propsValue;
|
|
18
|
+
const response = await httpClient.sendRequest({
|
|
19
|
+
method: HttpMethod.POST,
|
|
20
|
+
url: `${baseUrl}/ccaas/1/conversations/${conversationId}/messages`,
|
|
21
|
+
headers: { Authorization: `App ${apiKey}`, 'Content-Type': 'application/json' },
|
|
22
|
+
body: { from: senderNumber, to, channel: 'WHATSAPP', contentType: 'TEXT', content: { text: message } },
|
|
23
|
+
});
|
|
24
|
+
return response.body;
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
module.exports = { sendWhatsAppText };
|