public override void ParseElement(XmlElement element)
    {
        XmlNodeList
            resourcess = element.SelectNodes("resources"),
            descriptionss = element.SelectNodes("description"),
            assets,
            conditions,
            frontcolors,
            bordercolors,
            textcolors = element.SelectNodes("textcolor"),
            conversationsref = element.SelectNodes("conversation-ref"),
            voices = element.SelectNodes("voice"),
            actionss = element.SelectNodes("actions");

        string tmpArgVal;

        string characterId = element.GetAttribute("id");

        npc = new NPC(characterId);

        descriptions = new List<Description>();
        npc.setDescriptions(descriptions);

        if (element.SelectSingleNode("documentation") != null)
            npc.setDocumentation(element.SelectSingleNode("documentation").InnerText);

        foreach (XmlElement el in resourcess)
        {
            currentResources = new ResourcesUni();
            tmpArgVal = el.GetAttribute("name");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                currentResources.setName(el.GetAttribute(tmpArgVal));
            }

            assets = el.SelectNodes("asset");
            foreach (XmlElement ell in assets)
            {
                string type = "";
                string path = "";

                tmpArgVal = ell.GetAttribute("type");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    type = tmpArgVal;
                }
                tmpArgVal = ell.GetAttribute("uri");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    path = tmpArgVal;
                }
                currentResources.addAsset(type, path);
            }

            conditions = el.SelectNodes("condition");
            foreach (XmlElement ell in conditions)
            {
                currentConditions = new Conditions();
                new ConditionSubParser_(currentConditions, chapter).ParseElement(ell);
                currentResources.setConditions(currentConditions);
            }

            npc.addResources(currentResources);
        }

        foreach (XmlElement el in textcolors)
        {
            tmpArgVal = el.GetAttribute("showsSpeechBubble");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                npc.setShowsSpeechBubbles(tmpArgVal.Equals("yes"));
            }

            tmpArgVal = el.GetAttribute("bubbleBkgColor");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                npc.setBubbleBkgColor(tmpArgVal);
            }

            tmpArgVal = el.GetAttribute("bubbleBorderColor");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                npc.setBubbleBorderColor(tmpArgVal);
            }

            frontcolors = el.SelectNodes("frontcolor");
            foreach (XmlElement ell in frontcolors)
            {
                string color = "";

                tmpArgVal = ell.GetAttribute("color");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    color = tmpArgVal;
                }

                npc.setTextFrontColor(color);
            }

            bordercolors = el.SelectNodes("bordercolor");
            foreach (XmlElement ell in bordercolors)
            {
                string color = "";

                tmpArgVal = ell.GetAttribute("color");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    color = tmpArgVal;
                }

                npc.setTextBorderColor(color);
            }
        }

        foreach (XmlElement el in conversationsref)
        {
            string idTarget = "";

            tmpArgVal = el.GetAttribute("idTarget");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                idTarget = tmpArgVal;
            }

            conversationReference = new ConversationReference(idTarget);

            conditions = el.SelectNodes("condition");
            foreach (XmlElement ell in conditions)
            {
                currentConditions = new Conditions();
                new ConditionSubParser_(currentConditions, chapter).ParseElement(ell);

                conversationReference.setConditions(currentConditions);
            }

            conversationReference.setDocumentation(el.SelectSingleNode("documentation").InnerText);

            Action action = new Action(Action.TALK_TO);
            action.setConditions(conversationReference.getConditions());
            action.setDocumentation(conversationReference.getDocumentation());
            TriggerConversationEffect effect = new TriggerConversationEffect(conversationReference.getTargetId());
            action.getEffects().add(effect);
            npc.addAction(action);
        }

        foreach (XmlElement el in voices)
        {
            string voice = "";
            string response;
            bool alwaysSynthesizer = false;

            tmpArgVal = el.GetAttribute("name");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                voice = tmpArgVal;
            }

            tmpArgVal = el.GetAttribute("synthesizeAlways");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                response = tmpArgVal;
                if (response.Equals("yes"))
                    alwaysSynthesizer = true;
            }

            npc.setAlwaysSynthesizer(alwaysSynthesizer);
            npc.setVoice(voice);
        }

        foreach (XmlElement el in actionss)
        {
            new ActionsSubParser_(chapter, npc).ParseElement(el);
        }

        foreach (XmlElement el in descriptionss)
        {
            description = new Description();
            new DescriptionsSubParser_(description, chapter).ParseElement(el);
            this.descriptions.Add(description);
        }

        chapter.addCharacter(npc);
    }
예제 #2
0
 /// <summary>
 /// Deletes an existing activity in the conversation.
 /// Not implemented for this sample.
 /// </summary>
 /// <param name="turnContext">The context object for the turn.</param>
 /// <param name="reference">Conversation reference for the activity to delete.</param>
 /// <param name="cancellationToken">A cancellation token that can be used by other objects
 /// or threads to receive notice of cancellation.</param>
 /// <returns>A task that represents the work queued to execute.</returns>
 public override Task DeleteActivityAsync(ITurnContext turnContext, ConversationReference reference, CancellationToken cancellationToken)
 {
     throw new NotImplementedException();
 }
    /*
     * (non-Javadoc)
     *
     * @see es.eucm.eadventure.engine.loader.subparsers.SubParser#startElement(java.lang.string, java.lang.string,
     *      java.lang.string, org.xml.sax.Attributes)
     */
    public override void startElement(string namespaceURI, string sName, string qName, Dictionary<string, string> attrs)
    {
        // If no element is being subparsed
        if (subParsing == SUBPARSING_NONE)
        {

            // If it is a character tag, store the id of the character
            if (qName.Equals("character"))
            {
                string characterId = "";

                foreach (KeyValuePair<string, string> entry in attrs)
                    if (entry.Key.Equals("id"))
                        characterId = entry.Value.ToString();

                npc = new NPC(characterId);

                descriptions = new List<Description>();
                npc.setDescriptions(descriptions);
            }

            // If it is a resources tag, create the new resources, and switch the element being parsed
            else if (qName.Equals("resources"))
            {
                currentResources = new ResourcesUni();

                foreach (KeyValuePair<string, string> entry in attrs)
                {
                    if (entry.Key.Equals("name"))
                        currentResources.setName(entry.Value.ToString());
                }

                reading = READING_RESOURCES;
            }

            // If it is an asset tag, read it and add it to the current resources
            else if (qName.Equals("asset"))
            {
                string type = "";
                string path = "";

                foreach (KeyValuePair<string, string> entry in attrs)
                {
                    if (entry.Key.Equals("type"))
                        type = entry.Value.ToString();
                    if (entry.Key.Equals("uri"))
                        path = entry.Value.ToString();
                }

                // If the asset is not an special one
                //if( !AssetsController.isAssetSpecial( path ) )
                currentResources.addAsset(type, path);
            }

            // If it is a frontcolor or bordercolor tag, pick the color
            else if (qName.Equals("frontcolor") || qName.Equals("bordercolor"))
            {
                string color = "";

                // Pick the color
                foreach (KeyValuePair<string, string> entry in attrs)
                    if (entry.Key.Equals("color"))
                        color = entry.Value.ToString();

                // Set the color in the npc
                if (qName.Equals("frontcolor"))
                    npc.setTextFrontColor(color);
                if (qName.Equals("bordercolor"))
                    npc.setTextBorderColor(color);
            }

            else if (qName.Equals("textcolor"))
            {
                foreach (KeyValuePair<string, string> entry in attrs)
                {
                    if (entry.Key.Equals("showsSpeechBubble"))
                        npc.setShowsSpeechBubbles(entry.Value.ToString().Equals("yes"));
                    if (entry.Key.Equals("bubbleBkgColor"))
                        npc.setBubbleBkgColor(entry.Value.ToString());
                    if (entry.Key.Equals("bubbleBorderColor"))
                        npc.setBubbleBorderColor(entry.Value.ToString());
                }
            }

            // If it is a conversation reference tag, store the destination id, and switch the element being parsed
            else if (qName.Equals("conversation-ref"))
            {
                string idTarget = "";

                foreach (KeyValuePair<string, string> entry in attrs)
                    if (entry.Key.Equals("idTarget"))
                        idTarget = entry.Value.ToString();

                conversationReference = new ConversationReference(idTarget);
                reading = READING_CONVERSATION_REFERENCE;
            }

            // If it is a condition tag, create a new subparser
            else if (qName.Equals("condition"))
            {
                currentConditions = new Conditions();
                subParser = new ConditionSubParser(currentConditions, chapter);
                subParsing = SUBPARSING_CONDITION;
            }
            // If it is a voice tag, take the voice and the always synthesizer option
            else if (qName.Equals("voice"))
            {
                string voice = "";
                string response;
                bool alwaysSynthesizer = false;

                // Pick the voice and synthesizer option
                foreach (KeyValuePair<string, string> entry in attrs)
                {
                    if (entry.Key.Equals("name"))
                        voice = entry.Value.ToString();
                    if (entry.Key.Equals("synthesizeAlways"))
                    {
                        response = entry.Value.ToString();
                        if (response.Equals("yes"))
                            alwaysSynthesizer = true;
                    }

                }
                npc.setAlwaysSynthesizer(alwaysSynthesizer);
                npc.setVoice(voice);
            }

            else if (qName.Equals("actions"))
            {
                subParser = new ActionsSubParser(chapter, npc);
                subParsing = SUBPARSING_ACTIONS;
            }

            // If it is a description tag, create the new description (with its id)
            else if (qName.Equals("description"))
            {
                description = new Description();
                subParser = new DescriptionsSubParser(description, chapter);
                subParsing = SUBPARSING_DESCRIPTION;
            }

        }

        // If a condition or action is being subparsed, spread the call
        if (subParsing != SUBPARSING_NONE)
        {
            subParser.startElement(namespaceURI, sName, qName, attrs);
        }
    }
예제 #4
0
 /// <summary>
 /// Sends a proactive message from the bot to a conversation.
 /// </summary>
 /// <param name="claimsIdentity">A <see cref="ClaimsIdentity"/> for the conversation.</param>
 /// <param name="reference">A reference to the conversation to continue.</param>
 /// <param name="callback">The method to call for the resulting bot turn.</param>
 /// <param name="cancellationToken">Cancellation token.</param>
 /// <returns>A task that represents the work queued to execute.</returns>
 /// <remarks>Call this method to proactively send a message to a conversation.
 /// <para>This method registers the following services for the turn.<list type="bullet">
 /// <item><description><see cref="IIdentity"/> (key = "BotIdentity"), a claims claimsIdentity for the bot.
 /// </description></item>
 /// </list></para>
 /// </remarks>
 /// <seealso cref="BotAdapter.RunPipelineAsync(ITurnContext, BotCallbackHandler, CancellationToken)"/>
 public override async Task ContinueConversationAsync(ClaimsIdentity claimsIdentity, ConversationReference reference, BotCallbackHandler callback, CancellationToken cancellationToken)
 {
     using (var context = new TurnContext(this, reference.GetContinuationActivity()))
     {
         context.TurnState.Add <IIdentity>(BotIdentityKey, claimsIdentity);
         context.TurnState.Add <BotCallbackHandler>(callback);
         await RunPipelineAsync(context, callback, cancellationToken).ConfigureAwait(false);
     }
 }
예제 #5
0
        /// <summary>
        /// Create proactive context around conversation reference
        /// All middleware pipelines will be processed
        /// </summary>
        /// <param name="reference">reference to create context around</param>
        /// <param name="callback">callback where you can continue the conversation</param>
        /// <returns>task when completed</returns>
        public virtual async Task ContinueConversation(ConversationReference reference, Func <IBotContext, Task> callback)
        {
            var context = new BotContext(this, reference);

            await RunPipeline(context, callback).ConfigureAwait(false);
        }
예제 #6
0
 /// <summary>
 /// When overridden in a derived class, deletes an existing activity in the
 /// conversation.
 /// </summary>
 /// <param name="context">The context object for the turn.</param>
 /// <param name="reference">Conversation reference for the activity to delete.</param>
 /// <param name="cancellationToken">A cancellation token that can be used by other objects
 /// or threads to receive notice of cancellation.</param>
 /// <returns>A task that represents the work queued to execute.</returns>
 /// <remarks>The <see cref="ConversationReference.ActivityId"/> of the conversation
 /// reference identifies the activity to delete.</remarks>
 /// <seealso cref="ITurnContext.OnDeleteActivity(DeleteActivityHandler)"/>
 public abstract Task DeleteActivityAsync(ITurnContext context, ConversationReference reference, CancellationToken cancellationToken);
예제 #7
0
 /// <summary>
 /// Throws a <see cref="NotImplementedException"/> exception in all cases.
 /// </summary>
 /// <param name="turnContext">The context object for the turn.</param>
 /// <param name="reference">Conversation reference for the activity to delete.</param>
 /// <param name="cancellationToken">A cancellation token that can be used by other objects
 /// or threads to receive notice of cancellation.</param>
 /// <returns>A task that represents the work queued to execute.</returns>
 public override Task DeleteActivityAsync(ITurnContext turnContext, ConversationReference reference, CancellationToken cancellationToken)
 {
     return(Task.FromException(new NotImplementedException("Facebook adapter does not support deleteActivity.")));
 }
예제 #8
0
 /// <summary>
 /// Throws a <see cref="NotImplementedException"/> exception in all cases.
 /// </summary>
 /// <param name="turnContext">The context object for the turn.</param>
 /// <param name="reference">Conversation reference for the activity to delete.</param>
 /// <param name="cancellationToken">A cancellation token that can be used by other objects
 /// or threads to receive notice of cancellation.</param>
 /// <returns>A task that represents the work queued to execute.</returns>
 public override Task DeleteActivityAsync(ITurnContext turnContext, ConversationReference reference,
                                          CancellationToken cancellationToken)
 {
     return(Task.FromException <ResourceResponse>(
                new NotImplementedException("Infobip adapter does not support updateActivity.")));
 }
예제 #9
0
 public LocaleFinder(ConversationReference conversationReference, ResumptionContext resumptionContext)
 {
     SetField.NotNull(out this.conversationReference, nameof(conversationReference), conversationReference);
     SetField.NotNull(out this.resumptionContext, nameof(resumptionContext), resumptionContext);
 }
예제 #10
0
 public BotContext(Bot bot, ConversationReference conversationReference)
 {
     _bot = bot ?? throw new ArgumentNullException(nameof(bot));
     _conversationReference = conversationReference ?? throw new ArgumentNullException(nameof(conversationReference));
 }
예제 #11
0
 /// <summary>
 /// Implement deleting an activity in the conversation
 /// </summary>
 /// <param name="reference">Conversation reference of the activity being deleted.  </param>
 /// <returns></returns>
 public abstract Task DeleteActivity(ITurnContext context, ConversationReference reference);
예제 #12
0
        /// <summary>
        /// Create proactive context around conversation reference
        /// All middleware pipelines will be processed
        /// </summary>
        /// <param name="reference">reference to create context around</param>
        /// <param name="callback">callback where you can continue the conversation</param>
        /// <returns>task when completed</returns>
        public virtual Task ContinueConversation(ConversationReference reference, Func <ITurnContext, Task> callback)
        {
            var context = new TurnContext(this, reference.GetPostToBotMessage());

            return(RunPipeline(context, callback));
        }
 public ConnectionRequest(ConversationReference requestor)
 {
     Requestor = requestor;
     ResetConnectionRequestTime();
 }
예제 #14
0
        public async Task OnProcessRequest(IBotContext context, MiddlewareSet.NextDelegate next)
        {
            var activity = context.Request.AsMessageActivity();

            if (activity == null)
            {
                await next();
            }

            // Handle the message from functions contains ChatPlus's webhook response
            if (activity?.Type == ActivityTypes.Event)
            {
                Debug.WriteLine("*************************");
                Debug.WriteLine("Got event type message");
                Debug.WriteLine("*************************");
                string userId = "default-user"; // TODO hiroaki-honda remove this line and replace userId used as key to extract ConversationInformation from table storage. ("default-user" is the userId just for Hackfest).
                // string userId = Deserialize<Visitor>("visitor", (Activity)activity).visitor_id;
                ConversationReference conversationReference = await GetConversationReferenceByUserId(userId);

                switch (activity.From.Id)
                {
                case "WebhookStartChat":
                    string messageForSuccessToConnect = "Success to make a connection with call center agent. Please let us know what makes you in trouble.";
                    await SendProactiveMessage(context, conversationReference, messageForSuccessToConnect);

                    break;

                case "WebhookSendMessage":
                    string messageFromAgent = JsonConvert.DeserializeObject <ChatPlusInformation>(activity.Value.ToString()).message.text;
                    await SendProactiveMessage(context, conversationReference, messageFromAgent);

                    break;

                default:
                    throw new Exception("unexpected event type message");
                }
            }

            // Enqueue the message to hook the function which passes the message to agent if "IsConnectedToAgent" is true.
            var userState = context.GetUserState <BotUserState>();

            if (userState != null && userState.IsConnectedToAgent)
            {
                CloudStorageAccount account          = buildStorageAccount();
                CloudQueueClient    cloudQueueClient = account.CreateCloudQueueClient();
                CloudQueue          queue            = cloudQueueClient.GetQueueReference("message-from-user");
                var item = new ConversationInformation()
                {
                    ConversationReference = JsonConvert.SerializeObject(GetConversationReference((Microsoft.Bot.Schema.Activity)activity)),
                    MessageFromUser       = context.Request.Text
                };
                var message = new CloudQueueMessage(JsonConvert.SerializeObject(item));
                await queue.AddMessageAsync(message);

                return;
            }

            // Request to make a connection between user and agent
            if (activity != null &&
                !string.IsNullOrEmpty(activity.Text) &&
                activity.Text.ToLower().Contains(Commands.CommandRequestConnection))
            {
                // Store conversation reference (Use this info when send a proactive message to user after).
                await StoreConversationInformation(context);

                // TODO hiroaki-honda Implement the logic to hook the function which request connection to ChatPlus
                // Status: Ask chatplus to prepare the API which receive the request to connect to agent

                // Set connecting state true
                var state = context.GetUserState <BotUserState>();
                state.IsConnectedToAgent = true;

                await context.SendActivity("Now make a request for connection. Please wait a minutes.");
            }
            else
            {
                await next();
            }
        }