-
-
Save dfischer/79c4582c55a1cd8f40cabc84cbbf9c6e to your computer and use it in GitHub Desktop.
This file contains 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