Skip to content

Instantly share code, notes, and snippets.

@dfischer
Forked from gigobyte/FPasync.js
Created July 17, 2018 23:53
Show Gist options
  • Save dfischer/79c4582c55a1cd8f40cabc84cbbf9c6e to your computer and use it in GitHub Desktop.
Save dfischer/79c4582c55a1cd8f40cabc84cbbf9c6e to your computer and use it in GitHub Desktop.
// 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