@ebenos/messenger-adapter
Advanced tools
Comparing version 3.4.5 to 4.0.0-alpha.1
import { GenericAdapter, IInteraction } from '@ebenos/framework'; | ||
import { UserModel } from '@ebenos/framework'; | ||
import { Router } from 'express'; | ||
import { SenderFunction } from './sender'; | ||
import MessengerUser from './MessengerUser'; | ||
import { UserDataFields, MessagingOptions } from './interfaces/messengerAPI'; | ||
export interface MessengerWebhookOptions<T extends MessengerUser> { | ||
export interface MessengerWebhookOptions { | ||
webhookKey?: string; | ||
@@ -12,3 +12,2 @@ route?: string; | ||
pageToken: string; | ||
userModel?: UserModel<T>; | ||
} | ||
@@ -18,3 +17,3 @@ export interface MessengerOperations { | ||
} | ||
export default class MessengerAdapter<T extends MessengerUser> extends GenericAdapter<T, MessengerOperations> { | ||
export default class MessengerAdapter<T extends MessengerUser> extends GenericAdapter<MessengerOperations> { | ||
private webhookKey; | ||
@@ -27,7 +26,7 @@ private pageToken; | ||
sender: (actions: Array<IInteraction<MessagingOptions>>, type: 'ORDERED' | 'UNORDERED') => Promise<void>; | ||
constructor(options: MessengerWebhookOptions<T>, sendFunction?: SenderFunction, domain?: string); | ||
initWebhook(): void; | ||
webhook: Router; | ||
constructor(options: MessengerWebhookOptions, sendFunction?: SenderFunction, domain?: string); | ||
initialization(): void; | ||
private validationEndpoint; | ||
userLoader(): (id: string) => Promise<T>; | ||
} | ||
//# sourceMappingURL=adapter.d.ts.map |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -16,10 +7,11 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
const framework_1 = require("@ebenos/framework"); | ||
const express_1 = require("express"); | ||
const webhook_1 = __importDefault(require("./webhook")); | ||
const sender_1 = require("./sender"); | ||
const messaging_1 = __importDefault(require("../webhooks/messaging")); | ||
const MessengerUser_1 = __importDefault(require("./MessengerUser")); | ||
const MessengerUser_1 = require("./MessengerUser"); | ||
class MessengerAdapter extends framework_1.GenericAdapter { | ||
constructor(options, sendFunction, domain) { | ||
const { route = '/fb', webhookKey = 'ebony123', pageId, pageToken, userModel = MessengerUser_1.default } = options; | ||
super(userModel); | ||
const { route = '/fb', webhookKey = 'ebony123', pageId, pageToken } = options; | ||
super(); | ||
this.webhookKey = webhookKey; | ||
@@ -35,6 +27,7 @@ this.pageToken = pageToken; | ||
}; | ||
this.webhook = express_1.Router(); | ||
} | ||
initWebhook() { | ||
initialization() { | ||
const messaging = messaging_1.default({ | ||
userLoader: this.userLoader(), | ||
userLoader: MessengerUser_1.userLoader(this.pageToken), | ||
routers: this.routers, | ||
@@ -59,23 +52,4 @@ handlers: this.handlers | ||
} | ||
userLoader() { | ||
return (id) => __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const userData = yield framework_1.User.findByProviderId(id); | ||
if (!userData) { | ||
const newUser = new this.userModel({ | ||
id | ||
}, this.pageToken); | ||
yield newUser.getFacebookData(); | ||
yield newUser.save(); | ||
return newUser; | ||
} | ||
return new this.userModel(userData, this.pageToken); | ||
} | ||
catch (err) { | ||
throw err; | ||
} | ||
}); | ||
} | ||
} | ||
exports.default = MessengerAdapter; | ||
//# sourceMappingURL=adapter.js.map |
@@ -11,8 +11,8 @@ export interface SendAPIBody { | ||
export declare enum UserDataFields { | ||
firstName = 'first_name', | ||
lastName = 'last_name', | ||
profilePic = 'profile_pic', | ||
locale = 'locale', | ||
timezone = 'timezone', | ||
gender = 'gender' | ||
firstName = "first_name", | ||
lastName = "last_name", | ||
profilePic = "profile_pic", | ||
locale = "locale", | ||
timezone = "timezone", | ||
gender = "gender" | ||
} | ||
@@ -24,2 +24,2 @@ export interface MessagingOptions { | ||
} | ||
//# sourceMappingURL=messengerAPI.d.ts.map | ||
//# sourceMappingURL=messengerAPI.d.ts.map |
@@ -1,9 +0,10 @@ | ||
import { User } from '@ebenos/framework'; | ||
export default class MessengerUser extends User { | ||
import { DatabaseUser } from '@ebenos/framework'; | ||
export default class MessengerUser extends DatabaseUser { | ||
private getUserData; | ||
constructor(document: any, pageToken: string); | ||
handover(): Promise<this>; | ||
dehandover(): Promise<this>; | ||
constructor(databaseUser: DatabaseUser, pageToken: string); | ||
handover(): Promise<any>; | ||
dehandover(): Promise<any>; | ||
getFacebookData(): Promise<void>; | ||
} | ||
export declare function userLoader(pageToken: string): (id: string) => Promise<MessengerUser>; | ||
//# sourceMappingURL=MessengerUser.d.ts.map |
@@ -12,8 +12,9 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.userLoader = void 0; | ||
const framework_1 = require("@ebenos/framework"); | ||
const sender_1 = require("./sender"); | ||
const messengerAPI_1 = require("./interfaces/messengerAPI"); | ||
class MessengerUser extends framework_1.User { | ||
constructor(document, pageToken) { | ||
super(document); | ||
class MessengerUser extends framework_1.DatabaseUser { | ||
constructor(databaseUser, pageToken) { | ||
super(databaseUser.doc); | ||
const { getUserData } = sender_1.senderFactory(pageToken); | ||
@@ -58,2 +59,23 @@ this.getUserData = getUserData; | ||
exports.default = MessengerUser; | ||
function userLoader(pageToken) { | ||
return (id) => __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const userData = yield framework_1.DatabaseUser.findByProviderId(id); | ||
if (!userData) { | ||
const newUser = new MessengerUser(new framework_1.DatabaseUser({ | ||
id, | ||
data: {} | ||
}), pageToken); | ||
yield newUser.getFacebookData(); | ||
yield newUser.save(); | ||
return newUser; | ||
} | ||
return new MessengerUser(userData, pageToken); | ||
} | ||
catch (err) { | ||
throw err; | ||
} | ||
}); | ||
} | ||
exports.userLoader = userLoader; | ||
//# sourceMappingURL=MessengerUser.js.map |
import { MessagingEntry } from '../adapter/interfaces/webhook'; | ||
import { IRouters, EbonyHandlers, User } from '@ebenos/framework'; | ||
import { IRouters, EbonyHandlers } from '@ebenos/framework'; | ||
import MessengerUser from '../adapter/MessengerUser'; | ||
interface MessagingWebhookOptions<T extends User> { | ||
interface MessagingWebhookOptions<T extends MessengerUser> { | ||
routers: IRouters; | ||
@@ -6,0 +6,0 @@ userLoader: (id: string) => Promise<T>; |
@@ -51,3 +51,3 @@ "use strict"; | ||
if (referral.ref) { | ||
routerExists(routers.ReferralsRouter).referralsRouter(user, referral.ref); | ||
routerExists(routers.ReferralsRouter).referralsRouter(user, referral); | ||
return; | ||
@@ -66,3 +66,3 @@ } | ||
if (referral.ref) { | ||
routerExists(routers.ReferralsRouter).referralsRouter(user, referral.ref); | ||
routerExists(routers.ReferralsRouter).referralsRouter(user, referral); | ||
return; | ||
@@ -69,0 +69,0 @@ } |
{ | ||
"name": "@ebenos/messenger-adapter", | ||
"version": "3.4.5", | ||
"version": "4.0.0-alpha.1", | ||
"description": "Facebook SendAPI Library for the Ebony framework.", | ||
@@ -41,3 +41,3 @@ "main": "./build/index.js", | ||
"devDependencies": { | ||
"@ebenos/framework": "^3.4.5" | ||
"@ebenos/framework": "^4.0.0-alpha.1" | ||
}, | ||
@@ -50,3 +50,3 @@ "engines": { | ||
], | ||
"gitHead": "048b3816f680c6db9be8223503567c64ffbc89e3" | ||
"gitHead": "04583595fb6aef30da25b21674815e34db7b621b" | ||
} |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
54367
778
2