Created
July 3, 2018 19:27
-
-
Save fletcherist/bcc4b46746d3814a5b3b28293033d49e 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
alice.welcome((ctx) => { | |
ctx.confirm({ | |
reply: '18 есть?', | |
onYes: (ctx) => ctx.reply('добро пожаловать'), | |
onNo: (ctx) => ctx.reply('в другой раз'), | |
}) | |
}) | |
function aliceConfirmMiddleware() { | |
const store = new Map() | |
return (ctx) => { | |
// просто патчим метод (ну только по-другому, конечно же) | |
// это псевдокод | |
ctx.confirm = ({ | |
reply, | |
yes = button('да'), | |
no = button('нет'), | |
onYes, | |
onNo, | |
}) => { | |
// ... | |
store.set(ctx.sessionId, { | |
yes, | |
no, | |
onYes, | |
onNo, | |
}) | |
ctx.reply(reply) | |
} | |
// чекаем текущую команду | |
const data = store.get(ctx.sessionId) | |
if (data) { | |
// чекаем прошлый ответ (вообще там нажатие кнопки, ну да ладно) | |
if (ctx.req.payload === data.yes) { }) { | |
return data.onYes() | |
} else { | |
return data.onNo() | |
} | |
} | |
return ctx | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment