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

Is there anyway to configure the bot to send a message out (not just response).

Open lvmmth opened this issue 8 years ago • 8 comments

I want to configure my Skype bot to send message in group, or broadcast message to all user have added my bot. Is there anyway to do like this?

Thanks in advance. Joy

lvmmth avatar Mar 07 '18 10:03 lvmmth

Is it anything like ProActive mesage

MNHarun avatar Mar 08 '18 00:03 MNHarun

I think so, but there are many unknow in:

ConversationStarter.toId = message.From.Id;
ConversationStarter.toName = message.From.Name;
ConversationStarter.fromId = message.Recipient.Id;
ConversationStarter.fromName = message.Recipient.Name;
ConversationStarter.serviceUrl = message.ServiceUrl;
ConversationStarter.channelId = message.ChannelId;
ConversationStarter.conversationId = message.Conversation.Id;

lvmmth avatar Mar 08 '18 04:03 lvmmth

Are you using the .NET SDK or the nodejs SDK?

nodeomega avatar Mar 08 '18 23:03 nodeomega

@nodeomega I'm using the .NET SDK.

lvmmth avatar Mar 09 '18 02:03 lvmmth

I get this error message:

Dialogs\EchoDialog.cs(28,13): error CS0103: The name 'ConversationStarter' does not exist in the current context [D:\home\site\wwwroot\Microsoft.Bot.Sample.SimpleEchoBot.csproj] Dialogs\EchoDialog.cs(29,13): error CS0103: The name 'ConversationStarter' does not exist in the current context [D:\home\site\wwwroot\Microsoft.Bot.Sample.SimpleEchoBot.csproj] Dialogs\EchoDialog.cs(30,13): error CS0103: The name 'ConversationStarter' does not exist in the current context [D:\home\site\wwwroot\Microsoft.Bot.Sample.SimpleEchoBot.csproj] Dialogs\EchoDialog.cs(31,13): error CS0103: The name 'ConversationStarter' does not exist in the current context [D:\home\site\wwwroot\Microsoft.Bot.Sample.SimpleEchoBot.csproj] Dialogs\EchoDialog.cs(32,13): error CS0103: The name 'ConversationStarter' does not exist in the current context [D:\home\site\wwwroot\Microsoft.Bot.Sample.SimpleEchoBot.csproj] Dialogs\EchoDialog.cs(33,13): error CS0103: The name 'ConversationStarter' does not exist in the current context [D:\home\site\wwwroot\Microsoft.Bot.Sample.SimpleEchoBot.csproj] Dialogs\EchoDialog.cs(34,13): error CS0103: The name 'ConversationStarter' does not exist in the current context [D:\home\site\wwwroot\Microsoft.Bot.Sample.SimpleEchoBot.csproj] Dialogs\EchoDialog.cs(43,50): error CS0103: The name 'toId' does not exist in the current context [D:\home\site\wwwroot\Microsoft.Bot.Sample.SimpleEchoBot.csproj] Dialogs\EchoDialog.cs(43,55): error CS0103: The name 'toName' does not exist in the current context [D:\home\site\wwwroot\Microsoft.Bot.Sample.SimpleEchoBot.csproj] Dialogs\EchoDialog.cs(44,49): error CS0103: The name 'fromId' does not exist in the current context [D:\home\site\wwwroot\Microsoft.Bot.Sample.SimpleEchoBot.csproj] Dialogs\EchoDialog.cs(44,57): error CS0103: The name 'fromName' does not exist in the current context [D:\home\site\wwwroot\Microsoft.Bot.Sample.SimpleEchoBot.csproj] Dialogs\EchoDialog.cs(45,57): error CS0103: The name 'serviceUrl' does not exist in the current context [D:\home\site\wwwroot\Microsoft.Bot.Sample.SimpleEchoBot.csproj] Dialogs\EchoDialog.cs(48,30): error CS0128: A local variable named 'message' is already defined in this scope [D:\home\site\wwwroot\Microsoft.Bot.Sample.SimpleEchoBot.csproj] Dialogs\EchoDialog.cs(49,39): error CS0103: The name 'conversationId' does not exist in the current context [D:\home\site\wwwroot\Microsoft.Bot.Sample.SimpleEchoBot.csproj] Dialogs\EchoDialog.cs(49,80): error CS0103: The name 'channelId' does not exist in the current context [D:\home\site\wwwroot\Microsoft.Bot.Sample.SimpleEchoBot.csproj] Dialogs\EchoDialog.cs(52,37): error CS0103: The name 'channelId' does not exist in the current context [D:\home\site\wwwroot\Microsoft.Bot.Sample.SimpleEchoBot.csproj] Dialogs\EchoDialog.cs(58,17): error CS0103: The name 'conversationId' does not exist in the current context [D:\home\site\wwwroot\Microsoft.Bot.Sample.SimpleEchoBot.csproj] Dialogs\EchoDialog.cs(64,64): error CS0103: The name 'conversationId' does not exist in the current context [D:\home\site\wwwroot\Microsoft.Bot.Sample.SimpleEchoBot.csproj] Failed exitCode=1, command="D:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" "D:\home\site\wwwroot.\Microsoft.Bot.Sample.SimpleEchoBot.csproj" /nologo /verbosity:m /t:Build /p:AutoParameterizationWebConfigConnectionStrings=false;Configuration=Release;UseSharedCompilation=false /p:SolutionDir="D:\home\site\wwwroot..\" An error has occurred during web site deployment.

lvmmth avatar Mar 09 '18 07:03 lvmmth

This is my sourcecode in EchoDialog.cs, did I miss something?

`using System; using System.Threading.Tasks; using Microsoft.Bot.Connector; using Microsoft.Bot.Builder.Dialogs; using System.Net.Http;

namespace Microsoft.Bot.Sample.SimpleEchoBot { [Serializable] public class EchoDialog : IDialog { protected int count = 1; public async Task StartAsync(IDialogContext context) { context.Wait(MessageReceivedAsync); }

    public async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> argument)
    {
        var message = await argument;

        // Extract data from the user's message that the bot will need later to send an ad hoc message to the user. 
        // Store the extracted data in a custom class "ConversationStarter" (not shown here).
    
        ConversationStarter.toId = message.From.Id;
        ConversationStarter.toName = message.From.Name;
        ConversationStarter.fromId = message.Recipient.Id;
        ConversationStarter.fromName = message.Recipient.Name;
        ConversationStarter.serviceUrl = message.ServiceUrl;
        ConversationStarter.channelId = message.ChannelId;
        ConversationStarter.conversationId = message.Conversation.Id;
    
        // (Save this information somewhere that it can be accessed later, such as in a database.)
    
        await context.PostAsync("Hello user, good to meet you! I now know your address and can send you notifications in the future.");
        context.Wait(MessageReceivedAsync);
        
        
        // Use the data stored previously to create the required objects.
        var userAccount = new ChannelAccount(toId,toName);
        var botAccount = new ChannelAccount(fromId, fromName);
        var connector = new ConnectorClient(new Uri(serviceUrl));
        
        // Create a new message.
        IMessageActivity message = Activity.CreateMessageActivity();
        if (!string.IsNullOrEmpty(conversationId) && !string.IsNullOrEmpty(channelId))  
        {
            // If conversation ID and channel ID was stored previously, use it.
            message.ChannelId = channelId;
        }
        else
        {
            // Conversation ID was not stored previously, so create a conversation. 
            // Note: If the user has an existing conversation in a channel, this will likely create a new conversation window.
            conversationId = (await connector.Conversations.CreateDirectConversationAsync( botAccount, userAccount)).Id;
        }
        
        // Set the address-related properties in the message and send the message.
        message.From = botAccount;
        message.Recipient = userAccount;
        message.Conversation = new ConversationAccount(id: conversationId);
        message.Text = "Hello, this is a notification";
        message.Locale = "en-us";
        await connector.Conversations.SendToConversationAsync((Activity)message);
        
        

        
    }

    public async Task AfterResetAsync(IDialogContext context, IAwaitable<bool> argument)
    {
        var confirm = await argument;
        if (confirm)
        {
            this.count = 1;
            await context.PostAsync("Reset count.");
        }
        else
        {
            await context.PostAsync("Did not reset count.");
        }
        context.Wait(MessageReceivedAsync);
    }

}

}`

lvmmth avatar Mar 10 '18 04:03 lvmmth

Do you have the class definition handy for your ConversationStarter class?

nodeomega avatar Apr 02 '18 19:04 nodeomega

Closing this issue as there has been no reply for an extended period. If this issue persists, feel free to open a new support request. Thank you.

nodeomega avatar Apr 11 '18 23:04 nodeomega