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

send msg to multiple user in Microsoft Teams

Open bonny1001 opened this issue 8 years ago • 5 comments

Bot Info

  • SDK Platform: .NET
  • SDK Version: 3.12.2.4
  • Active Channels: MS Teams
  • Deployment Environment: Azure Bot Service,

Issue Description

Now i can send msg to a single MS Teams user successfully But now i want to send msg to multiple users one time or send msg to a team channle when i run the code as below, i get an exception ":Incorrect conversation creation parameters"

Code Example

string toId = "xxx";
string toName = "xx";
string fromId = "xxx";
string fromName = "xxx";
string serviceUrl = "xxx";
string channelId = "xxx";
string conversationId = "";
string step = "";
try
{
    var userAccount = new ChannelAccount(toId, toName);
    var botAccount = new ChannelAccount(fromId, fromName);
    var connector = new ConnectorClient(new Uri(serviceUrl));
    MicrosoftAppCredentials.TrustServiceUrl(serviceUrl);

	List<ChannelAccount> participants = new List<ChannelAccount>();
        participants.Add(new ChannelAccount("xx", "xx"));
	participants.Add(new ChannelAccount("xxx", "xx"));


	using (System.IO.StreamWriter sw = new System.IO.StreamWriter(logFile, true))
	{

    sw.WriteLine(System.DateTime.Now + ";" + string.Format(@"ChannelId:'{0}';conversationId:'{1}';conversationName:'{2}';fromId:'{3}';fromName:'{4}';id:'{5}';recepientId:'{6}';recepientName:'{7}';ServiceUrl:'{8}'"
                                                    , channelId, conversationId, "", fromId, fromName, "", toId, toName, serviceUrl));
	}

	IMessageActivity message = Activity.CreateMessageActivity();

        step += "1";
	ConversationParameters cpMessage = new ConversationParameters(true, botAccount, participants, "topicName");
        step += "2";
	conversationId = connector.Conversations.CreateConversation(cpMessage).Id;
	step += "3";

	//}
	using (System.IO.StreamWriter sw = new System.IO.StreamWriter(logFile, true))
	{
		sw.WriteLine("new conversationId :" + conversationId);
	}

	message.From = botAccount;
	message.Recipient = userAccount;
	message.Conversation = new ConversationAccount(id: conversationId);
        message.Text = "hellohahaha";
	message.Locale = "en-Us";

	await connector.Conversations.SendToConversationAsync((Activity) message);				
}
catch (Exception ex)
{
	string aa = ex.Message;
	using (System.IO.StreamWriter sw = new System.IO.StreamWriter(logFile, true))
	{
		sw.WriteLine("exception :" + aa + ";step:" + step);
	}
}

Reproduction Steps

1. 2. 3.

Expected Behavior

users added all can receive the message

Actual Results

get an Exception ":Incorrect conversation creation parameters"

bonny1001 avatar Jun 05 '18 09:06 bonny1001

We are facing issue in sending message to a single MS Teams user. Can you please let us know how can we send message to a single MS Teams user?

rajeshlohar avatar Jul 12 '18 05:07 rajeshlohar

@bonny1001 Was the bot loaded from the store, or is this a side loaded bot?

@rajeshlohar Please review the docs on Proactive Messaging in MSTeams: https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/bots/bot-conversations/bots-conv-proactive and let us know if you run into any issues.

EricDahlvang avatar Jul 13 '18 22:07 EricDahlvang

This is side loaded bot.

rajeshlohar avatar Jul 14 '18 04:07 rajeshlohar

We tried above docs on Proactive Message, but getting error "Operation returned an invalid status code 'NotFound". Below is the code :

    string serviceUrl = "https://xxxxxxxx.xxxxxxxxx.com/api/messages";
        var connector = new ConnectorClient(new Uri(serviceUrl));
        MicrosoftAppCredentials.TrustServiceUrl(serviceUrl);
        var BotAccount = new ChannelAccount("xxxxxxxxxxxx","xxxxxxxx");
        var channelAccount= new ChannelAccount("xxxxxxxxxxxx","xxxxxxxx");;
        try
        {
            var ConversationId = connector.Conversations.CreateOrGetDirectConversation(BotAccount, channelAccount, TenantId);
            Activity userMessage = new Activity
            {                    
                Text = "hello",
                Type = ActivityTypes.Message,
                Conversation=new ConversationAccount
                {
                    Id=ConversationId.Id
                }
            };
            await connector.Conversations.SendToConversationAsync(ConversationId.Id, userMessage);

rajeshlohar avatar Jul 16 '18 05:07 rajeshlohar

Thank you for opening an issue against the Bot Framework SDK v3. As part of the Bot Framework v4 release, we’ve moved all v3 work to a new repo located at https://github.com/microsoft/botbuilder-v3. We will continue to support and offer maintenance updates to v3 via this new repo.

From now on, https://github.com/microsoft/botbuilder repo will be used as hub, with pointers to all the different SDK languages, tools and samples repos.

As part of this restructuring, we are closing all tickets in this repo.

For defects or feature requests, please create a new issue in the new Bot Framework v3 repo found here: https://github.com/microsoft/botbuilder-v3/issues

For Azure Bot Service Channel specific defects or feature requests (e.g. Facebook, Twilio, Teams, Slack, etc.), please create a new issue in the new Bot Framework Channel repo found here: https://github.com/microsoft/botframework-services/issues

For product behavior, how-to, or general understanding questions, please use Stackoverflow. https://stackoverflow.com/search?q=bot+framework

Thank you.

The Bot Framework Team

JasonSowers avatar Oct 01 '18 20:10 JasonSowers