Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Sparkbot "limit_to_domain" config will raise an exception when receiving a message  #1208

@JavaCS3

Description

@JavaCS3

Botkit version: 0.6
OS: MacOS (It's not related to OS)

var controller = Botkit.sparkbot({
    debug: true,
    log: true,
    limit_to_domain: ['XXXX.com'],  // enable this
    // limit_to_org: 'my_cisco_org_id',
    public_address: process.env.public_address,
    ciscospark_access_token: process.env.access_token,
   ...
});

When bot received any message from cisco spark. It will get

An error occured in the ingest middleware:  TypeError: Cannot read property 'toLowerCase' of undefined
    at Ware.limitUsers (/SECRET/node_modules/botkit/lib/CiscoSparkbot.js:164:34)
    at Ware.<anonymous> (/SECRET/node_modules/wrap-fn/index.js:45:19)
    at next (/SECRET/node_modules/ware/lib/index.js:85:20)
    at Ware.run (/SECRET/node_modules/ware/lib/index.js:88:3)
    at Object.Botkit.botkit.ingest (/SECRET/node_modules/botkit/lib/CoreBot.js:72:34)
    at Object.Sparkbot.controller.handleWebhookPayload (/SECRET/node_modules/botkit/lib/CiscoSparkbot.js:322:20)
    at /SECRET/components/routes/incoming_webhooks.js:17:20
    at Layer.handle [as handle_request] (/SECRET/node_modules/express/lib/router/layer.js:95:5)
    at next (/SECRET/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/SECRET/node_modules/express/lib/router/route.js:112:3)

I have found the root cause. It looks like Cisco Spark API have changed. Cisco Spark sent

{
    "id": "XXXXX",
    "name": "Cisco Spark bot created with Botkit, override me before going to production",
    "targetUrl": "https://XXXXX/ciscospark/receive",
    "resource": "messages",
    "event": "created",
    "orgId": "XXXXX",
    "createdBy": "XXXXX",
    "appId": "XXXXX",
    "ownedBy": "creator",
    "status": "active",
    "created": "2018-01-02T08:40:09.105Z",
    "actorId": "XXXXX",
    "data": {
        "id": "XXXXX",
        "roomId": "XXXXX",
        "roomType": "direct",
        "personId": "XXXXX",
        "personEmail": "XXXXX@XXXX.com",
        "created": "2018-01-12T07:59:43.433Z"
    }
}

There's no "user" field in the message.
In this code
It will acquire "user" field.
So it raised an exception.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions