@ebenos/viber-adapter
Advanced tools
Comparing version 4.0.0-alpha.28 to 4.0.0-alpha.29
@@ -22,15 +22,15 @@ "use strict"; | ||
}; | ||
this.webhook = express_1.default(); | ||
this.webhook = (0, express_1.default)(); | ||
const { route = '/viber/webhook', authToken, welcomeMessage } = options; | ||
this.route = route; | ||
this.authToken = authToken; | ||
this.sender = sender_1.default(this.authToken); | ||
this.sender = (0, sender_1.default)(this.authToken); | ||
this.welcomeMessage = welcomeMessage; | ||
} | ||
initialization() { | ||
this.webhook.use(body_parser_1.json()); | ||
this.webhook.use((0, body_parser_1.json)()); | ||
this.webhook.post(this.route, viberWebhookFactory(this.routers, this.handlers, this.welcomeMessage)); | ||
} | ||
setWebhook(url) { | ||
return requests_1.setWebhook(url + this.route, this.authToken); | ||
return (0, requests_1.setWebhook)(url + this.route, this.authToken); | ||
} | ||
@@ -52,28 +52,31 @@ } | ||
} | ||
function handleTextOnly(m, user, textHandler) { | ||
if (textHandler !== undefined) { | ||
textHandler({ text: m.text }, undefined, user); | ||
function handleTextMessage(m, user, textHandler, routers) { | ||
if (textHandler === undefined) { | ||
console.log('No text handler'); | ||
return; | ||
} | ||
console.log('No text handler'); | ||
return; | ||
} | ||
function handleTextMessage(m, user, textHandler, routers) { | ||
const text = m.text ? m.text : 'user_send_location'; | ||
const location = m.type === 'location' ? m.location : undefined; | ||
let tracking_data; | ||
try { | ||
const parsedTrackingData = JSON.parse(m.tracking_data); | ||
if (tracking_data_1.isPostbackTrackingData(parsedTrackingData)) { | ||
const payload = JSON.stringify({ | ||
type: parsedTrackingData.type + m.text.replace(' ', ''), | ||
data: parsedTrackingData.data | ||
}); | ||
routerExists(routers.PostbackRouter).objectPayloadHandler(payload, user); | ||
return; | ||
} | ||
handleTextOnly(m, user, textHandler); | ||
return; | ||
// Tracking Data is an object | ||
tracking_data = JSON.parse(m.tracking_data); | ||
} | ||
catch { | ||
handleTextOnly(m, user, textHandler); | ||
// Tracking Data is a string | ||
tracking_data = m.tracking_data; | ||
} | ||
if ((0, tracking_data_1.isPostbackTrackingData)(tracking_data)) { | ||
// Tracking Data is a postback | ||
const payload = JSON.stringify({ | ||
type: tracking_data.type, | ||
text, | ||
location, | ||
tracking_data | ||
}); | ||
routerExists(routers.PostbackRouter).objectPayloadHandler(payload, user); | ||
return; | ||
} | ||
textHandler({ text, tracking_data, location }, undefined, user); | ||
return; | ||
} | ||
@@ -85,6 +88,7 @@ function viberWebhookFactory(routers, handlers, welcomeMessage) { | ||
case 'text': | ||
case 'location': | ||
handleTextMessage(e.message, user, handlers.text, routers); | ||
return; | ||
default: | ||
if (message_types_1.isMediaMessage(e.message)) { | ||
if ((0, message_types_1.isMediaMessage)(e.message)) { | ||
if (handlers.attachment !== undefined) { | ||
@@ -91,0 +95,0 @@ handlers.attachment(user, e.message); |
@@ -12,3 +12,3 @@ "use strict"; | ||
}; | ||
return viberRequest_1.default('set_webhook', body, authToken); | ||
return (0, viberRequest_1.default)('set_webhook', body, authToken); | ||
} | ||
@@ -21,5 +21,5 @@ exports.setWebhook = setWebhook; | ||
}; | ||
return viberRequest_1.default('send_message', body, authToken); | ||
return (0, viberRequest_1.default)('send_message', body, authToken); | ||
} | ||
exports.sendMessage = sendMessage; | ||
//# sourceMappingURL=requests.js.map |
@@ -9,3 +9,3 @@ "use strict"; | ||
async function viberRequest(path, data, authToken) { | ||
const res = await node_fetch_1.default(viberUrl + path, { | ||
const res = await (0, node_fetch_1.default)(viberUrl + path, { | ||
method: 'POST', | ||
@@ -12,0 +12,0 @@ body: JSON.stringify(data), |
@@ -40,2 +40,3 @@ export declare type MessageType = 'text' | 'picture' | 'video' | 'file' | 'sticker' | 'contact' | 'url' | 'location'; | ||
type: 'location'; | ||
text?: string; | ||
location: { | ||
@@ -42,0 +43,0 @@ lat: number; |
@@ -13,3 +13,3 @@ "use strict"; | ||
case 'message': | ||
await requests_1.sendMessage(a.id, a.message.serialize(), viberToken); | ||
await (0, requests_1.sendMessage)(a.id, a.message.serialize(), viberToken); | ||
break; | ||
@@ -16,0 +16,0 @@ case 'typing_on': |
{ | ||
"name": "@ebenos/viber-adapter", | ||
"version": "4.0.0-alpha.28", | ||
"version": "4.0.0-alpha.29", | ||
"description": "Viber adapter for the Ebony framework.", | ||
@@ -31,14 +31,14 @@ "main": "./build/index.js", | ||
"dependencies": { | ||
"@types/body-parser": "^1.19.0", | ||
"@types/express": "^4.17.11", | ||
"@types/node-fetch": "^2.5.8", | ||
"body-parser": "^1.19.0", | ||
"express": "^4.17.1", | ||
"node-fetch": "^2.6.1" | ||
"node-fetch": "^2.6.6" | ||
}, | ||
"devDependencies": { | ||
"@ebenos/framework": "^4.0.0-alpha.28" | ||
"@ebenos/framework": "^4.0.0-alpha.29", | ||
"@types/body-parser": "^1.19.2", | ||
"@types/express": "^4.17.13", | ||
"@types/node-fetch": "^2.5.12" | ||
}, | ||
"engines": { | ||
"node": ">=8.9.0" | ||
"node": ">=14.0.0" | ||
}, | ||
@@ -48,3 +48,3 @@ "files": [ | ||
], | ||
"gitHead": "d56f9b1c64cf59fc8ca220609139ccea7b19d425" | ||
"gitHead": "18fd89bfbc610610c8edc8c5ea32a7c616341b11" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30414
3
414
4
- Removed@types/body-parser@^1.19.0
- Removed@types/express@^4.17.11
- Removed@types/node-fetch@^2.5.8
- Removed@types/body-parser@1.19.5(transitive)
- Removed@types/connect@3.4.38(transitive)
- Removed@types/express@4.17.21(transitive)
- Removed@types/express-serve-static-core@4.19.6(transitive)
- Removed@types/http-errors@2.0.4(transitive)
- Removed@types/mime@1.3.5(transitive)
- Removed@types/node@22.10.0(transitive)
- Removed@types/node-fetch@2.6.12(transitive)
- Removed@types/qs@6.9.17(transitive)
- Removed@types/range-parser@1.2.7(transitive)
- Removed@types/send@0.17.4(transitive)
- Removed@types/serve-static@1.15.7(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedform-data@4.0.1(transitive)
- Removedundici-types@6.20.0(transitive)
Updatednode-fetch@^2.6.6