Created
July 14, 2018 14:37
-
-
Save gigobyte/960e78b9cb209b90edf6fb2a42cccac7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Separate url validation logic from Replies.sayInvalidLinkedInUrl side effect. | |
// This way you can reuse this function in other methods | |
const getUrlFromEvent = (event) => Maybe.of(event) | |
.filter(x => event.message.nlp.entities.url) | |
.filter(x => event.message.nlp.entities.url[0].domain !== 'linkedin.com') | |
.chain(x => Maybe.fromNullable(extract(event.message.nlp.entities.url))) | |
consume.onUserState('preferences/linkedin/url', ({ event, userId }) => getUrlFromEvent(event) | |
.caseOf({ | |
Just: (url) => Promise.all([User.updatePreferences(userId, {linkedIn: url[0]}), Dispatch.linkedInUrlReceived({ userId })]), | |
Nothing: () => Replies.sayInvalidLinkedInUrl({ userId }) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment