-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add smart reply to remove boilerplate #53
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't try this yet, but going to now. Changes requested re: wanting more info on WIP
comments.
src/app.js
Outdated
@@ -181,6 +202,7 @@ class Messenger extends EventEmitter { | |||
.then((session) => this.saveSession(session)); | |||
} | |||
|
|||
// WIP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unclear what this WIP is referring to. Doesn't seem to match anything in the follow-up tasks...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, I was marking that these methods are vestigial from the beauty lens bot and they're kinda dead code at this point but we want to bring them back eventually. I didn't want to start yak shaving to bring them up to "code" 😸 to keep this PR smaller. But I wanted to leave a mark to remind myself to stop trying to work on them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, cool. Seems like good candidates for linking to issues.
src/app.js
Outdated
debug('onAuth for user:%d with param: %j', senderId, optinRef); | ||
} | ||
|
||
/* | ||
This is not an event triggered by Messenger, it is the post-back from the | ||
static Facebook login page that is made to look similar to an 'event' | ||
*/ | ||
// WIP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto here.
src/app.js
Outdated
@@ -355,17 +378,25 @@ class Messenger extends EventEmitter { | |||
return this.cache.set(session._key, session); | |||
} | |||
|
|||
send(recipientId/*: string|number */, messageData/*: Object */, pageId/*: string|void */)/* Promise<Object> */ { | |||
send(arg1/*: string|number */, arg2/*: string|number|Object */, arg3/*: Object|void */)/* Promise<Object> */ { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is going to be refactored into simpler logic, have you considered making the new paradigm a wrapper function for the time being and then we replace send
down the line? This would also mean changing the third arg to the pageAccessToken
rather than the ID, but I think that's a fair tradeoff since that is currently an optional arg and it would reduce LOC.
pageSend(pageId, recipientId, messageData) {
const pageAccessToken = this.pages[pageId];
return this.send(recipientId, messageData, pageAccessToken);
}
send(recipientId, messageData, accessToken) {
// kills ~10 LOC here
const pageAccessToken = accessToken || config.get('messenger.pageAccessToken');
const options = {... }
debug('message.send: %j', options);
return reqPromise.post(options)
...
}
Later on, the contents of send
can be merged into pageSend
or send
can be replace by pageSend
.
Both approaches are a bit awkward TBH. I find the above alternative easier to follow and to me, it communicates more about where the code is headed. It does come with downsides though. In either case, I think some additional comments or a link to an issue describe the next steps would provide some useful context.
TL;DR - I'm okay with this even though it is a bit tough to read, but wanted to propose an alternative as a thought exercise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been working on this concept on and off for a few weeks. I think I thought of that approach but I can't remember why I didn't stick with it. I'll give it a shot with pageSend
👍
Tried with my test bot via |
Noticed that the previous version did not allow a single page to send with
|
I'm moving this back to WIP to change some design. After IRL discussion, moving towards forcing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok took off WIP again. I'm not liking how many LOC this is but it's almost all docs and tests.
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/T123456/B33Z/Pajamas | ||
SLACK_CHANNEL=channel | ||
LOG_FILE=/var/log/my-bot/chat.log | ||
ALLOW_CONFIG_MUTATIONS=Y |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ALLOW_CONFIG_MUTATIONS
is the new config I needed. This will let you do PORT=-1
in #54 without potentially confusing users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working on a test bot with both the old and new way, without passing in pages
to the Messenger
constructor.
this.pages = {[config.get('facebook.pageId')]: config.get('messenger.pageAccessToken')}; | ||
} else { | ||
this.pages = {}; | ||
debug("MISSING options.pages; you won't be able to reply or get profile information"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is my favorite line in this PR. It shows how those two config variables are actually optional depending on what your bot is doing. While the SDK doesn't exactly gracefully degrade, we could make it.
I did a test w/ slack ghost just now too and 👍 |
Why are we doing this?
Multitenant bots will have to specify page id when sending a message. To do that now, they would have to do
messenger.send(senderId, responseObj, session._pageId)
, which is very not ideal. Luckily everything has been backwards compatible and the page routing logic has been hidden. This adds another backwards compatible change so bots only have to doreply(responseObj
), and the state required has been tucked into thereply
function.Some other changes:
test.env
. I didn't want to add another.env
, but I needed stuff in the test environment that isn't applicable to users. This means we can add comments toexample.env
closes #50
Did you document your work?
Some missing docs have been added to the Readme, new functionality is there too, and existing docs are updated.
How can someone test these changes?
Steps to manually verify the change:
npm i
npm t
Link to an existing bot and make sure your existing bot works:
npm link
npm link launch-vehicle-fbm
What possible risks or adverse effects are there?
send
is changed. But it's done in a backwards compatible change. That means that the arguments are currently introspected before being used, which adds a mess of code. We just have to hope to mature enough so the page config transition lets us delete the adapter code.send(senderId, responseObj, pageId)
but here I changed my mind and went withsend(pageId, senderId, responseObj)
because puttingpageId
at the end looked so hacky. Now the arguments are in a more logical order.What are the follow-up tasks?
log a deprecation warning when bot is launched w/o page configAre there any known issues?
None
Did the test coverage decrease?
new code is covered