Example #1
0
        /// <summary>
        /// Called when the dialog is started and pushed onto the dialog stack.
        /// </summary>
        /// <param name="dc">The <see cref="DialogContext"/> for the current turn of conversation.</param>
        /// <param name="options">Optional, initial information to pass to the dialog.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects
        /// or threads to receive notice of cancellation.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            // Pull some values we stored in turnState so we can continue the conversation on the SMS adapter
            // Note: this is a bit hacky, we may need to find a more elegant way of doing this.
            var acsSmsAdapter = dc.Context.TurnState.Get <AcsSmsAdapter>();
            var bot           = dc.Context.TurnState.Get <IBot>();
            var convoState    = dc.Context.TurnState.Get <ConversationState>();
            var config        = dc.Context.TurnState.Get <IConfiguration>();

            var smsNumber = SmsNumber.GetValue(dc.State);
            // Manually create a conversation reference for ACS_SMS so we can proactively start a conversation there.
            var smsCref = new ConversationReference
            {
                User         = new ChannelAccount(smsNumber),
                Bot          = new ChannelAccount(config.GetSection("acsSmsAdapterSettings")["AcsPhoneNumber"], "bot"),
                Conversation = new ConversationAccount(false, null, smsNumber),
                ChannelId    = "ACS_SMS"
            };

            // Capture the context so we can send it in the continue conversation event.
            var messageData = MessageData.GetValue(dc.State);

            async Task BotCallback(ITurnContext context, CancellationToken ct)
            {
                // Set the problem in value property of the continuation activity.
                context.Activity.Value = messageData;
                await bot.OnTurnAsync(context, ct);
            }

            // send proactive message with convRef to start SMS
            await acsSmsAdapter.ContinueConversationAsync(config["MicrosoftAppId"], smsCref, BotCallback, cancellationToken);

            // End the action.
            return(await dc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false));
        }
Example #2
0
 }                                                   // !!
 public ValueSmsThing(IDontKnow value, SmsNumber sms)
 {
     Value = value;
     Sms   = sms;
 }