1

I have looked at the proactiveMessages example and the createNewConveration bot examples provided in GIT. Both examples show that a conversation is started with a channel account after it initially interacts with the bot. I need to create a bot that can start a conversation with a user (specifically SMS) that HAS NEVER interacted with my bot previously. I have the valid ID (in this case sms number) to create a channel account object and the twilio phone number that I want to use as the producer of the message activity.

2 Questions: 1) In order to use a connector client and create a direct conversation is it necessary for the user to have previously interacted with my bot? If so, is there a way to load this channel account data into bot data store in order for me to create a conversation? 2) Will there be a future version that will allow our bot (via api) to start conversations with valid channel accounts? The api is a bit misleading by allowing me to CREATE a conversation. It should be named "resumeConversation".

Jay Tina
  • 107
  • 7

1 Answers1

2

I was able to start a conversation via the connector client with service url: https://sms.botframework.com and the bot app creds. I noticed in my trace logger that channel account id contains the country code in the sms number. In this case the channel accountId should be in this format +1[areacode][number]. My proactive greeting was sent successfully. So I believe the SMS channel will allow conversations to be started from BOT to user.

ServiceUrl in this case is https://sms.botframework.com for sms channel. The

 var serviceUrl = GetServiceUrlByChannelId(channel);
  MicrosoftAppCredentials.TrustServiceUrl(serviceUrl, DateTime.Now.AddDays(7)); //todo change magic number
  var account = new MicrosoftAppCredentials([MicrosoftAppId], [MicrosoftAppPassword]);

  _connector = new ConnectorClient(new Uri(serviceUrl), account);

  var botAccount = new ChannelAccount { Id = bot.Id, Name = bot.Name };
  var toAccount = new ChannelAccount { Id = recipient.Id, Name = recipient.Name };

  if (!MicrosoftAppCredentials.IsTrustedServiceUrl(serviceUrl)) {
    throw new Exception("Cannot create conversation! Service URL is not trusted!");
  }

  var conversationResponse = _connector.Conversations.CreateDirectConversation(botAccount, toAccount);
Jay Tina
  • 107
  • 7
  • Hey @jay-tina can you please share how you posted the bot app creds to the end point? – jsw324 Jun 23 '17 at 16:34
  • I just added a code snippet to my answer @jsw324. Does this answer your question? I'm unsure on what endpoint you are trying to invoke. With the ConnectorClient instance and the newly created conversationId I can now send an message to the end user (conversationId and serviceURL). – Jay Tina Jun 25 '17 at 03:56
  • got it! Thanks a lot! – jsw324 Jun 25 '17 at 21:34