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

Auto message chat room

Open SirWintour opened this issue 10 years ago • 3 comments

Is it possible for the bot to automatically message a chat room? I have made a timer that works and made that send a message, but it requires that you have at least written to the bot first. This is a problem if the bot crashes and needs a restart, so is there another way? P.S. I stored the session in a global variable so it could be used later.

SirWintour avatar Aug 25 '16 13:08 SirWintour

Some channels require that the bot be added to the chat room or spoken to by the user first.

If you have state you'd like to persist across bot process exist, then use the bot state service.

https://docs.botframework.com/en-us/technical-faq/#what-is-the-difference-between-proactive-and-reactive

willportnoy avatar Aug 25 '16 17:08 willportnoy

is there an example of proactive messaging? I have the following use cases.

  1. to initiative a conversation with a user on a data event.
  2. to prompt the user if he has been idle for some time.

ubreddy avatar Aug 26 '16 08:08 ubreddy

Thank you @willportnoy that helped me understand what i needed. I have now made it message me by itself.

For @ubreddy, if you need an example i have the code i use to make it work, just put it in a function, then you can call it asynchronously.

var bot = new builder.UniversalBot(connector);

var infff = {
        id: "FGhqhkzF6pcJHf6",
       channelId :"skype",
        user: {
                id: "",
                name: ""
        },
        conversation: {
                id: "29:1ePXXswdbe1zU2-Li7U-jXwrSQOQsM1mg8Ec7RGIzE30"
        },
        bot: {
                id: "28:ec29aa9c-d8f9-489a-b1d1-21d8541afb61",
                name: "UpBot"
        },
        serviceUrl: "https://skype.botframework.com",
        useAuth: true
};


var reply = new builder.Message()
    .address(infff)
    .text("This is an automated message");
bot.send(reply);

I've got this information by printing the session.message.address as a string, when a user is messaging the bot, using console.log("FROM : "+JSON.stringify(session.message.address));.

This code isn't finished but i hope you get the idea, how it works and hope you can use it.

SirWintour avatar Aug 26 '16 08:08 SirWintour