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

Equivalent of session.sendMessage on v3

Open matheus208 opened this issue 10 years ago • 3 comments

Using Node.js version 3.1.1

On v1, we had Session.sendMessage, where we could have a JSON be sent exactly as is to the desired channel. That was useful for quick testing and implementing stuff that's not yet implemented on the lib.

I don't seem to be able to use it on v3. I get "[TypeError: session.sendMessage is not a function]"

Is there an alternative to sending raw output to the channels? Using session.send doesn't seem to work.

matheus208 avatar Jul 20 '16 20:07 matheus208

This was changed to sourceEvent() in v3, and separated from the send action itself. With sourceEvent(), you can specify per-channel channelData. Example sending a custom message for Telegram:

var reply = new builder.Message(session);
reply.sourceEvent({
    telegram: {
        method: "sendMessage",
        parameters: {
            text: "<b>sample</b>",
            parse_mode: "HTML"
        }
    }
})
session.send(reply);

eanders-ms avatar Jul 21 '16 05:07 eanders-ms

Oh I hadn't come across this method on the documentation. Thank you!

For any Googlers that arrive on this with the same problem. Here is an example for sending an "account linking" card on Facebook:

            session.send(new builder.Message(session)
                    .sourceEvent({
                    facebook: {
                        notification_type: "REGULAR",
                        attachment: {
                            type: "template",
                            payload: {
                                template_type: "generic",
                                elements: [{
                                    title: "Welcome to M-Bank",
                                    image_url: "http://www.example.com/images/m-bank.png",
                                    buttons: [{
                                        type: "account_link",
                                        url: "http://localhost:9090/site/entrar-standalone"
                                    }]
                                }]
                            }
                        }
                    }
                }));

matheus208 avatar Jul 21 '16 13:07 matheus208

@matheus208 Hello , matheus could you guide me on what should happen on the back-end side for authorization please? I have a feeling it's a very complex process Feels like this should work but don't understand the redirect process https://gist.github.com/miki2826/76653b715c85d39181f0a57143f7a35c

in res.redirect(req.query.redirect_uri + '&authorization_code=' + req.user.id); what is the redirect_uri feels like this should be the address where my bot lives and I'm passing it an authorzation code to confirm the login ? But for this to work I have a feeling this express backend and the bot must live in the same code base which is not the case currently. For the bot I'm using claudia bot builder and it lives in a lambda function and this express backend lives on my local machine.

cAstraea avatar Mar 18 '17 08:03 cAstraea