コード例 #1
0
        public IHttpActionResult webhook([FromBody] LineWebhookModels data)
        {
            if (data == null)
            {
                return(BadRequest());
            }
            if (data.events == null)
            {
                return(BadRequest());
            }

            foreach (Event e in data.events)
            {
                if (e.type == EventType.message)
                {
                    ReplyBody rb = new ReplyBody()
                    {
                        replyToken = e.replyToken,
                        messages   = procMessage(e.message)
                    };
                    Reply reply = new Reply(rb);
                    reply.send();
                }
            }
            return(Ok(data));
        }
コード例 #2
0
 private RpcMessage GenerateReply(ReplyBody replyBody) =>
 new RpcMessage
 {
     Xid  = this.xid,
     Body = new Body
     {
         MessageType = MessageType.Reply,
         ReplyBody   = replyBody
     }
 };
コード例 #3
0
        public Reply(ReplyBody body)
        {
            //--- set header and body required infos ---
            req             = WebRequest.Create(API_URL);
            req.Method      = "POST";
            req.ContentType = "application/json";
            req.Headers["Authorization"] = "Bearer " + WebConfigurationManager.AppSettings["AccessToken"];

            // --- format to json and add to request body ---
            using (var streamWriter = new StreamWriter(req.GetRequestStream()))
            {
                string data = JsonConvert.SerializeObject(body);
                streamWriter.Write(data);
                streamWriter.Flush();
            }
        }
コード例 #4
0
        private async void ReplyButton_ClickAsync(object sender, EventArgs e)
        {
            if (tid.Text.Length != 0 && IsLoggded != false)
            {
                Tuple <bool, string> Result = await tsdmHelper.ReplyAsync(tid.Text, ReplyBody.Text);

                if (Result.Item1)
                {
                    ReplyBody.Clear();
                    MessageBox.Show(Result.Item2);
                }
                else
                {
                    MessageBox.Show(Result.Item2);
                }
            }
        }
コード例 #5
0
        public void FindKeywords()
        {
            KeywordList keywordList = new KeywordList();
            // Initialize a bucket to hold the keywords found
            List <string> thisQuestionsKeywords = new List <string>();

            // Start with header - cannot be null
            string[] headerKeywords = ReplyBody.Split(' ');

            // Find useful header keywords and convert to lowercase
            for (int i = 0; i < headerKeywords.Length; i += 1)
            {
                // Create variable to hold lowercase version through each loop
                string lowercaseVersion = headerKeywords[i].ToLower();
                // If not already in list and is useful
                if (!thisQuestionsKeywords.Contains(lowercaseVersion) && !keywordList.NotUsefulKeywords.Contains(lowercaseVersion))
                {
                    thisQuestionsKeywords.Add(lowercaseVersion);
                }
            }

            // Add all the found keywords (hopefully) to the FQ's keyword list
            keywords.AddRange(thisQuestionsKeywords);
        }
コード例 #6
0
        public ActionResult LineBot(string destination, LINEModel data)
        {
            if (data == null || data.events == null)
            {
                return(Json("BadRequest"));
            }
            string replyToken = data.events[0].replyToken;

            if (data.events[0].message.text == "推薦")
            {
                UriBuilder uriBuilder = new UriBuilder(Request.Url)
                {
                    Path = Url.Action("ByteImage", "Product", new { area = "ProductDisplay" })
                };
                string url = uriBuilder.ToString();
                ReplyBody <Line_Template> _Reply = new ReplyBody <Line_Template>()
                {
                    replyToken = replyToken,
                    messages   = linemesssage.Line_Templates(url)
                };
                LINE_Reply <Line_Template> reply = new LINE_Reply <Line_Template>(_Reply);
                reply.send();
            }
            else
            {
                ReplyBody <SendMessage> _Reply = new ReplyBody <SendMessage>()
                {
                    replyToken = replyToken,
                    messages   = procMessage(data.events[0].message, destination)
                };
                LINE_Reply <SendMessage> reply = new LINE_Reply <SendMessage>(_Reply);
                reply.send();
            }

            return(Json("Hi", JsonRequestBehavior.AllowGet));
        }
コード例 #7
0
        /// <summary>
        /// Set user mailbox Out of Office state.
        /// </summary>
        /// <param name="mailAddress">User's email address.</param>
        /// <param name="password">Password of user mailbox.</param>
        /// <param name="isOOF">If true, set OOF state, else make sure OOF state is not set (clear OOF state).</param>
        /// <returns>If the operation succeed then return true, otherwise return false.</returns>
        public bool SetUserOOFSettings(string mailAddress, string password, bool isOOF)
        {
            using (ExchangeServiceBinding service = new ExchangeServiceBinding())
            {
                service.Url = Common.GetConfigurationPropertyValue(Constants.SetOOFWebServiceURL, this.Site);
                if (service.Url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
                {
                    this.AcceptServerCertificate();
                }

                service.Credentials = new System.Net.NetworkCredential(mailAddress, password);

                EmailAddress emailAddress = new EmailAddress
                {
                    Address = mailAddress, Name = string.Empty
                };
                UserOofSettings userSettings = new UserOofSettings
                {
                    // Identify the external audience.
                    ExternalAudience = ExternalAudience.Known
                };

                // Create the OOF reply messages.
                ReplyBody replyBody = new ReplyBody
                {
                    Message = Constants.MessageOfOOFReply
                };

                userSettings.ExternalReply = replyBody;
                userSettings.InternalReply = replyBody;

                // Set OOF state.
                if (isOOF)
                {
                    userSettings.OofState = OofState.Enabled;
                }
                else
                {
                    userSettings.OofState = OofState.Disabled;
                }

                // Create the request.
                SetUserOofSettingsRequest request = new SetUserOofSettingsRequest
                {
                    Mailbox         = emailAddress,
                    UserOofSettings = userSettings
                };

                bool success = false;

                try
                {
                    SetUserOofSettingsResponse response = service.SetUserOofSettings(request);
                    if (response.ResponseMessage.ResponseCode == ResponseCodeType.NoError)
                    {
                        success = true;
                    }
                }
                catch (System.Xml.Schema.XmlSchemaValidationException e)
                {
                    // Catch the following critical exceptions, other unexpected exceptions will be emitted to protocol test framework.
                    Site.Log.Add(LogEntryKind.Debug, "An XML schema exception happened. The exception type is {0}.\n The exception message is {1}.", e.GetType().ToString(), e.Message);
                }
                catch (System.Xml.XmlException e)
                {
                    Site.Log.Add(LogEntryKind.Debug, "An XML schema exception happened. The exception type is {0}.\n The exception message is {1}.", e.GetType().ToString(), e.Message);
                }
                catch (System.Reflection.TargetException e)
                {
                    Site.Log.Add(LogEntryKind.Debug, "An operation exception happened when invoke Soap operation. The exception type is {0}.\n The exception message is {1}.", e.GetType().ToString(), e.Message);
                    throw;
                }
                catch (System.IO.IOException e)
                {
                    Site.Log.Add(LogEntryKind.Debug, "An IO exception happened when invoke Soap operation. The exception type is {0}.\n The exception message is {1}.", e.GetType().ToString(), e.Message);
                    throw;
                }

                return(success);
            }
        }