botman / web-widget

MIT License
39 stars 69 forks source link

Add userId param to widgetOpened event #39

Open sasha-x opened 5 years ago

sasha-x commented 5 years ago

If I am trying to start conversation with user from widgetOpened event, like this:

//index.html
var botmanWidget = {
sendWidgetOpenedEvent: 1
}
//bot.php
$botman->hears('(.*)', function ($bot){
    $bot->startConversation(new WelcomeConversation());
});

I see in my cache conversation duplicates (and in UI too):

root@scw:~# redis-cli KEYS '*'
1) "botman:cache:conversation-da39a3ee5e6b4b0d3255bfef95601890afd80709-da39a3ee5e6b4b0d3255bfef95601890afd80709"
2) "botman:cache:conversation-0409cb8558ad20d53c230f23e83cc64e15b6fa70-0409cb8558ad20d53c230f23e83cc64e15b6fa70"

The first hash is constantly equals sha1("") . The reason is widgetOpened event, which raise first instance of conversation, has no binding to any user.

With my fix all seems to work ok.

sasha-x commented 5 years ago

@mpociot , could you plz pay some attention to PRs? There are several other points which may become issues or PRs in main botman repo.

EranGrin commented 7 months ago

Great, I'll add it to here https://www.npmjs.com/package/botman-extended-web-widget