botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

[Slack] New bot receives duplicate messages?

Open spawn-guy opened this issue 9 years ago • 10 comments

System Information

  • SDK Language: Node.js
  • SDK Version: 3.9.0
  • Development Environment: other/AWS

Bot Info

  • Bot name: inn-bot-verlofapp
  • Bot handle: VerlofBot
  • App ID: b8376aa0-6e5e-4562-a883-43b7dcc104d8
  • Connected channels: Skype, Slack

Issue Description

I receive 2 messages with each Slack message sent via Direct message to bot.

Steps to Reproduce the Issue

A couple of other users reported the same thing here https://docs.microsoft.com/en-us/bot-framework/channel-connect-slack and an Older bot works fine and receives 1 message.

Expected Behavior

receive 1 message

Actual Results

{
    "type": "message",
    "timestamp": "2017-08-17T15:21:34.1389722Z",
    "text": "hello",
    "attachments": [],
    "entities": [],
    "sourceEvent": {
        "SlackMessage": {
            "type": "message",
            "channel": "D6...06",
            "user": "U0...C1",
            "text": "hello",
            "ts": "1502983293.000444",
            "source_team": "T0...US",
            "team": "T0...US"
        },
        "ApiToken": "xoxb-22...09-1fQ...R7J"
    },
    "address": {
        "id": "925...310",
        "channelId": "slack",
        "user": {
            "id": "U0...C1:T0...US",
            "name": "paul"
        },
        "conversation": {
            "isGroup": false,
            "id": "B6...SA:T0...US:D6...06"
        },
        "bot": {
            "id": "B6...SA:T0...US",
            "name": "verlofbot"
        },
        "serviceUrl": "https://slack.botframework.com"
    },
    "source": "slack",
    "agent": "botbuilder",
    "user": {
        "id": "U0...C1:T0...US",
        "name": "paul"
    }
}
{
    "type": "message",
    "timestamp": "2017-08-17T15:21:34.3226653Z",
    "text": "hello",
    "attachments": [],
    "entities": [],
    "sourceEvent": {
        "SlackMessage": {
            "token": "F80...gf7",
            "team_id": "T0...US",
            "api_app_id": "A6...RN",
            "event": {
                "type": "message",
                "user": "U0...C1",
                "text": "hello",
                "ts": "1502983293.000444",
                "channel": "D6...06",
                "event_ts": "1502983293.000444"
            },
            "type": "event_callback",
            "authed_users": [
                "U6...SR"
            ],
            "event_id": "Ev...DZ",
            "event_time": 1502983293
        },
        "ApiToken": "xoxb-22...09-1fQ...R7J"
    },
    "address": {
        "id": "09d...154",
        "channelId": "slack",
        "user": {
            "id": "U0...C1:T0...US",
            "name": "paul"
        },
        "conversation": {
            "isGroup": false,
            "id": "B6...SA:T0...US:D6...06"
        },
        "bot": {
            "id": "B6...SA:T0...US",
            "name": "verlofbot"
        },
        "serviceUrl": "https://slack.botframework.com"
    },
    "source": "slack",
    "agent": "botbuilder",
    "user": {
        "id": "U0...C1:T0...US",
        "name": "paul"
    }
}

spawn-guy avatar Aug 17 '17 15:08 spawn-guy

to overcome this I started filtering messages like that

bot.use({
    botbuilder: (session, next) => {     
        if (session.message.address.channelId === 'slack') {
            if (session.message.sourceEvent.SlackMessage) {
                if (session.message.sourceEvent.SlackMessage.type === 'message') {
                    return;
                }
            }
        }
        next();
    }
});

spawn-guy avatar Aug 18 '17 11:08 spawn-guy

Glad to hear you found a way to get it working.

JasonSowers avatar Aug 18 '17 15:08 JasonSowers

thanks for the update @spawn-guy

nwhitmont avatar Aug 18 '17 21:08 nwhitmont

@JasonSowers @nwhitmont however, this is NOT a problem with my Bot.

I think this is a problem with Platform Itself! With the specific Slack channel. That exists with Newer deployments(connections). As I have another working Bot that doesn't require this hack/override.

PS: I haven't really found a page where I can report this problem other than here.

spawn-guy avatar Aug 21 '17 12:08 spawn-guy

This is the correct place to report issues. 👍

JasonSowers avatar Aug 21 '17 15:08 JasonSowers

update: I Stopped receiving double messages! Hurray! However, I stopped receiving messages with type==message.... so I will update my snippet, as I was filtering out the wrong type of messages :/

spawn-guy avatar Aug 23 '17 07:08 spawn-guy

@nwhitmont, @spawn-guy - I'm experiencing the same issue. Why was this closed? Was there ever a proper fix to this? Is it expected that we use @spawn-guy's monkey patch for the slack channel forever or until Slack changes something?

astjohn avatar Sep 11 '17 02:09 astjohn

+1 to @astjohn message above. I am also having the same problem.

an0o0nym avatar Sep 18 '17 15:09 an0o0nym

I'm seeing this as well, running a simple bot from the examples:

var restify = require('restify'); var builder = require('botbuilder');

// Setup Restify Server var server = restify.createServer(); server.listen(process.env.port || process.env.PORT || 3978, function () { console.log('%s listening to %s', server.name, server.url); });

// Create chat connector for communicating with the Bot Framework Service var connector = new builder.ChatConnector({ appId: process.env.MICROSOFT_APP_ID, appPassword: process.env.MICROSOFT_APP_PASSWORD });

// Listen for messages from users server.post('/api/messages', connector.listen());

// Receive messages from the user and respond by echoing each message back (prefixed with 'You said:') var bot = new builder.UniversalBot(connector, function (session) { console.log(session.message.text); console.log(JSON.stringify(session.message, null, 2)); session.send("You said2: %s", session.message.text); });

daviande avatar Sep 18 '17 16:09 daviande

I'm also seeing this, though I am using C#. Will file a new issue.

IanLeatherbury avatar Sep 22 '17 18:09 IanLeatherbury