wingbot-facebook
Advanced tools
Comparing version 2.1.5 to 2.5.0-alpha.1
{ | ||
"name": "wingbot-facebook", | ||
"version": "2.1.5", | ||
"version": "2.5.0-alpha.1", | ||
"description": "Facebook messenger plugin for wingbot", | ||
@@ -50,3 +50,3 @@ "main": "src/main.js", | ||
"sinon": "^6.3.5", | ||
"wingbot": "^2.0.0" | ||
"wingbot": "^2.5.0-alpha.14" | ||
}, | ||
@@ -59,4 +59,4 @@ "dependencies": { | ||
"peerDependencies": { | ||
"wingbot": "^2.0.0" | ||
"wingbot": "^2.5.0-alpha.14" | ||
} | ||
} |
@@ -125,2 +125,4 @@ /* | ||
// | ||
const messageSender = new FacebookSender( | ||
@@ -137,7 +139,7 @@ options, | ||
if (message.take_thread_control) { | ||
const takeFromSelf = `${message.take_thread_control | ||
.previous_owner_app_id}` === this._options.appId; | ||
const takeFromSelf = !this._options.appId | ||
|| `${message.take_thread_control.previous_owner_app_id}` === this._options.appId; | ||
const appIdInMetaData = message.take_thread_control | ||
.metadata === this._options.appId; | ||
const appIdInMetaData = this._options.appId | ||
&& message.take_thread_control.metadata === this._options.appId; | ||
@@ -184,2 +186,4 @@ if (this._options.takeThreadAction && takeFromSelf && !appIdInMetaData) { | ||
// | ||
if (!event) { | ||
@@ -213,4 +217,10 @@ return Promise.resolve({ status: 201 }); | ||
if (PROCESS_EVENTS.some(e => typeof message[e] !== 'undefined')) { | ||
const senderId = (message.sender && message.sender.id) || null; | ||
let senderId = null; | ||
if (message.sender && message.sender.id) { | ||
senderId = message.sender.id; | ||
} else if (message.optin && message.optin.user_ref) { | ||
senderId = message.optin.user_ref; | ||
} | ||
if (!eventsBySenderId.has(senderId)) { | ||
@@ -217,0 +227,0 @@ eventsBySenderId.set(senderId, []); |
@@ -32,3 +32,3 @@ /* | ||
if (this._userRef) { | ||
if (incommingMessage.optin) { | ||
this._replaceRecipient = { | ||
@@ -39,4 +39,2 @@ recipient: { user_ref: this._userRef } | ||
this._gotUserId = null; | ||
this.url = 'https://graph.facebook.com/v2.8/me'; | ||
@@ -145,12 +143,2 @@ | ||
const hasRecipientId = res && typeof res === 'object' && res.recipient_id; | ||
if (hasRecipientId && this._resolveRef) { | ||
this._replaceRecipient = { | ||
// @ts-ignore | ||
recipient: { id: res.recipient_id } | ||
}; | ||
this._resolveRef({ senderId: res.recipient_id }); | ||
} | ||
return res; | ||
@@ -166,27 +154,31 @@ } catch (e) { | ||
send (payload) { | ||
if (payload.recipient && this._userRef && this._gotUserId === null) { | ||
// we will be waiting for ref | ||
this._gotUserId = new Promise((resolve) => { | ||
this._resolveRef = (data = null) => { | ||
this._resolveRef = null; | ||
resolve(data); | ||
async modifyStateAfterLoad (state, processor) { | ||
if (this._incommingMessage.prior_message) { | ||
const { identifier } = this._incommingMessage.prior_message; | ||
const refState = await processor.stateStorage.getState(identifier, state.pageId); | ||
if (refState) { | ||
return { | ||
state: refState.state | ||
}; | ||
}); | ||
} | ||
} | ||
super.send(payload); | ||
if (state._replaceRecipient) { | ||
this._replaceRecipient = state._replaceRecipient; | ||
} | ||
return null; | ||
} | ||
async modifyStateBeforeStore () { | ||
if (this._userRef && !this._gotUserId) { | ||
throw new Error('No text message was sent, when optin arrived!'); | ||
if (this._replaceRecipient) { | ||
return { _replaceRecipient: this._replaceRecipient }; | ||
} | ||
if (this._gotUserId) { | ||
return this._gotUserId; | ||
} | ||
return null; | ||
} | ||
} | ||
module.exports = FacebookSender; |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
69972
4
706
1