예제 #1
0
        public virtual async Task sBot(IDialogContext context, IAwaitable <IMessageActivity> argument)//subsrcibing action.
        {
            var value = await argument;

            toId           = value.From.Id;
            toName         = value.From.Name;
            fromId         = value.Recipient.Id;
            fromName       = value.Recipient.Name;
            serviceURL     = value.ServiceUrl;
            channelID      = value.ChannelId;
            conversationID = value.Conversation.Id;

            string choice = Convert.ToString(value.Text).ToUpper();

            if (choice == "1")
            {
                Models.DBotDBEntities db = new Models.DBotDBEntities();
                Models.DbotTable      tb = db.DbotTables.Single(x => x.OrderNumber == orderNumber);
                tb.fromID         = fromId;
                tb.fromName       = fromName;
                tb.toID           = toId;
                tb.toName         = toName;
                tb.serviceURL     = serviceURL;
                tb.channelID      = channelID;
                tb.conversationID = conversationID;
                db.SaveChanges();
                await context.PostAsync("Yaya!Added");
            }
            else
            {
                await context.PostAsync("No problem!");
            }
            context.Wait(usertBot);
        }
예제 #2
0
        public virtual async Task pBot(IDialogContext context, IAwaitable <IMessageActivity> argument)//admin confirmation
        {
            var    value  = await argument;
            string choice = Convert.ToString(value.Text);

            Models.DBotDBEntities db = new Models.DBotDBEntities();
            var broCode = (from adminTable in db.adminTable1
                           where adminTable.username == "Admin"
                           select adminTable.pwd);
            string broCode1 = broCode.Single();

            if (choice == broCode1)
            {
                await context.PostAsync("Hey sumi!!!Do I need to broadcast notification");

                context.Wait(aBot);
            }
            else
            {
                await context.PostAsync("Sorry!you are not an admin");

                context.Wait(usertBot);
            }
        }
예제 #3
0
        //public virtual async Task wBot(IDialogContext context, IAwaitable<IMessageActivity> argument)
        //{
        //    await context.PostAsync("Hi Awesome ! I am delivery bot!Just tell me your order number");
        //    context.Wait(oBot);
        //}

        public virtual async Task oBot(IDialogContext context, IAwaitable <IMessageActivity> argument)//display the status
        {
            var value     = await argument;
            var connector = new ConnectorClient(new Uri(value.ServiceUrl));

            orderNumber = Convert.ToString(value.Text);
            Models.DBotDBEntities db = new Models.DBotDBEntities();
            var sStatus = (from DbotTable in db.DbotTables
                           where DbotTable.OrderNumber == orderNumber
                           select DbotTable.Status);

            status = Convert.ToString(sStatus.FirstOrDefault());
            var dDate = (from DbotTable in db.DbotTables
                         where DbotTable.OrderNumber == orderNumber
                         select DbotTable.Date);

            date = Convert.ToString(dDate.FirstOrDefault());
            var dOrderName = (from DbotTable in db.DbotTables
                              where DbotTable.OrderNumber == orderNumber
                              select DbotTable.OrderName);

            OrderName = Convert.ToString(dOrderName.FirstOrDefault());
            var dTags = (from DbotTable in db.DbotTables
                         where DbotTable.OrderNumber == orderNumber
                         select DbotTable.PTAGS);

            tags = Convert.ToString(dTags.FirstOrDefault());

            var dimageLink = (from adTable in db.adTables
                              where adTable.Tags == tags
                              select adTable.PhotoLinks);

            imageLink = Convert.ToString(dimageLink.FirstOrDefault());

            var dproductLink = (from adTable in db.adTables
                                where adTable.Tags == tags
                                select adTable.ProductLinks);

            productLink = Convert.ToString(dproductLink.FirstOrDefault());



            if (status == null || date == null)
            {
                await context.PostAsync("No such record");

                context.Wait(usertBot);
            }
            else
            {
                Activity replyToConversation = (Activity)context.MakeMessage();
                replyToConversation.Attachments = new List <Attachment>();
                AdaptiveCard card = new AdaptiveCard();
                card.Body.Add(new TextBlock()
                {
                    Text   = "Result",
                    Size   = TextSize.Normal,
                    Weight = TextWeight.Bolder
                });
                card.Body.Add(new TextBlock()
                {
                    Text = "Order Name: " + OrderName
                });
                card.Body.Add(new TextBlock()
                {
                    Text = "Delivery Date: " + date + " , " + "Delivery status: " + status
                });
                card.Body.Add(new TextBlock()
                {
                    Text   = "This can be handy",
                    Size   = TextSize.Normal,
                    Weight = TextWeight.Bolder
                });
                card.Body.Add(new Image()
                {
                    Url   = imageLink,
                    Size  = ImageSize.Stretch,
                    Style = ImageStyle.Normal
                });
                card.Actions.Add(new OpenUrlAction()
                {
                    Url   = productLink,
                    Type  = "Action.OpenUrl",
                    Title = "Buy"
                });



                Attachment attachment = new Attachment()
                {
                    ContentType = AdaptiveCard.ContentType,
                    Content     = card
                };
                replyToConversation.Attachments.Add(attachment);
                await connector.Conversations.SendToConversationAsync(replyToConversation);

                context.Wait(msBot);
            }
        }
예제 #4
0
        public async Task aBot(IDialogContext context, IAwaitable <IMessageActivity> argument)//broadcasts the message
        {
            var      result = await argument;
            Activity replyToConversation = (Activity)context.MakeMessage();

            replyToConversation.Attachments = new List <Attachment>();
            AdaptiveCard card = new AdaptiveCard();


            Models.DBotDBEntities db = new Models.DBotDBEntities();
            var sendLists            = (from DbotTable in db.DbotTables
                                        where DbotTable.conversationID != null
                                        select DbotTable)
                                       .ToList();

            foreach (var sendList in sendLists)
            {
                toId           = sendList.toID;
                toName         = sendList.toName;
                fromId         = sendList.fromID;
                fromName       = sendList.fromName;
                serviceURL     = sendList.serviceURL;
                conversationID = sendList.conversationID;
                channelID      = sendList.channelID;
                status         = sendList.Status;
                date           = sendList.Date;

                var userAccount = new ChannelAccount(toId, toName);
                var botAccount  = new ChannelAccount(fromId, fromName);
                var connector   = new ConnectorClient(new Uri(serviceURL));

                IMessageActivity message = Activity.CreateMessageActivity();
                if (!string.IsNullOrEmpty(conversationID) && !string.IsNullOrEmpty(channelID))
                {
                    replyToConversation.ChannelId = channelID;
                }
                else
                {
                    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 = "Delivery status: " + status + " .Delivery date: " + date;
                //message.Locale = "en-Us";
                replyToConversation.From         = botAccount;
                replyToConversation.Recipient    = userAccount;
                replyToConversation.Conversation = new ConversationAccount(id: conversationID);
                replyToConversation.Locale       = "en-Us";

                card.Body.Add(new TextBlock()
                {
                    Text   = "Daily Update",
                    Size   = TextSize.Large,
                    Weight = TextWeight.Bolder
                });
                card.Body.Add(new TextBlock()
                {
                    Text = "Delivery status: " + status
                });
                card.Body.Add(new TextBlock()
                {
                    Text = "Delivery Date: " + date
                });

                Attachment attachment = new Attachment()
                {
                    ContentType = AdaptiveCard.ContentType,
                    Content     = card
                };
                card.Speak = "Update coming";
                replyToConversation.Attachments.Add(attachment);


                await connector.Conversations.SendToConversationAsync(replyToConversation);
            }
        }