Example #1
0
 private void sndMsg1()
 {
     Thread.Sleep(10 * 1000);
     if (_instMsgMod != null)
     {
         _instMsgMod.BeginSendMessage(txtResponse1.Text, StartConversationCallback, null);
     }
 }
        public LyncConversationHandler(ITelegramBotClient bot)
        {
            _bot = bot;
            _initClient();


            string[]     targetContactUris = { "sip:[email protected]" };
            LyncClient   client            = LyncClient.GetClient();
            Conversation conv = client.ConversationManager.AddConversation();

            foreach (string target in targetContactUris)
            {
                conv.AddParticipant(client.ContactManager.GetContactByUri(target));
            }
            InstantMessageModality m = conv.Modalities[ModalityTypes.InstantMessage] as InstantMessageModality;

            m.BeginSendMessage("Test Message", null, null);


            Microsoft.Win32.SystemEvents.SessionSwitch += (s, e) =>
            {
                if (e.Reason == SessionSwitchReason.SessionLock)
                {
                    _isSessionLock = true;
                }
                else if (e.Reason == SessionSwitchReason.SessionUnlock)
                {
                    _isSessionLock = false;
                }
            };
        }
Example #3
0
        void StartConversation(string myRemoteParticipantUri, string MSG)
        {
            foreach (var con in _conversationManager.Conversations)
            {
                if (con.Participants.Where(p => p.Contact.Uri == "sip:" + myRemoteParticipantUri).Count() > 0)
                {
                    if (con.Participants.Count == 2)
                    {
                        con.End();
                        break;
                    }
                }
            }

            Conversation _Conversation = _conversationManager.AddConversation();

            _Conversation.AddParticipant(_lyncClient.ContactManager.GetContactByUri(myRemoteParticipantUri));


            Dictionary <InstantMessageContentType, String> messages = new Dictionary <InstantMessageContentType, String>();

            messages.Add(InstantMessageContentType.PlainText, MSG);
            InstantMessageModality m = (InstantMessageModality)_Conversation.Modalities[ModalityTypes.InstantMessage];

            m.BeginSendMessage(messages, null, messages);
            LogMessage(myRemoteParticipantUri, MSG);
        }
Example #4
0
        internal void SendMessage(string contactUri, string imText)
        {
            try
            {
                if (_Client.State == ClientState.SignedIn)
                {
                    ConversationManager myConversationManager = _Client.ConversationManager;
                    Conversation        myConversation        = myConversationManager.AddConversation();
                    Participant         myParticipant         = myConversation.AddParticipant(_Client.ContactManager.GetContactByUri(contactUri));

                    if (myParticipant.IsSelf == false)
                    {
                        if (myConversation.State == ConversationState.Active && myConversation.Properties.ContainsKey(ConversationProperty.Subject))
                        {
                            myConversation.Properties[ConversationProperty.Subject] = SUBJECT;
                        }

                        if (myConversation.Modalities.ContainsKey(ModalityTypes.InstantMessage))
                        {
                            InstantMessageModality imModality = (InstantMessageModality)myConversation.Modalities[ModalityTypes.InstantMessage];
                            if (imModality.CanInvoke(ModalityAction.SendInstantMessage))
                            {
                                Dictionary <InstantMessageContentType, string> textMessage = new Dictionary <InstantMessageContentType, string>();
                                textMessage.Add(InstantMessageContentType.PlainText, SUBJECT + " : " + imText);

                                imModality.BeginSendMessage(textMessage, SendMessageCallback, imModality);
                            }
                        }
                    }
                }
            }
            catch
            {
            }
        }
        public async Task SendMessageToUser(string message)
        {
            sender.BeginSetComposing(true, null, null);
            await Task.Delay(3000);

            sender.BeginSendMessage(message, AfterMessageSent, null);
        }
        private void OnAllRecipientsAdded(Conversation currentConversation)
        {
            InstantMessageModality imModality = currentConversation.Modalities[ModalityTypes.InstantMessage] as InstantMessageModality;

            IDictionary <InstantMessageContentType, string> textMessage = new Dictionary <InstantMessageContentType, string>();

            textMessage.Add(InstantMessageContentType.PlainText, _message);

            if (imModality.CanInvoke(ModalityAction.SendInstantMessage))
            {
                IAsyncResult asyncResult = imModality.BeginSendMessage(textMessage, ar => { SendMessageCallback(imModality, ar); }, null);
                if (!_sendIMEvent.WaitOne(75000))
                {
                    Trace.WriteLine($"SendIM action failed in timeout recipients = {string.Join(", ", _recipients)}");
                    SendIMTimeout = true;
                }
                else
                {
                    //if at the end of the send, it remains only 1 participant (me) ==> All other participants are offline
                    //AllPArticipantsOffline = (currentConversation.Participants.Count = 1)

                    Trace.WriteLine($"SendIM action succedeed recipients = {string.Join(", ", _recipients)}");
                    Thread.Sleep(250);
                }
            }
        }
        void Conversation_ParticipantAdded(object sender, ParticipantCollectionChangedEventArgs e)
        {
            // add event handlers for modalities of participants other than self participant:
            if (e.Participant.IsSelf == false)
            {
                if (((Conversation)sender).Modalities.ContainsKey(ModalityTypes.InstantMessage))
                {
                    ((InstantMessageModality)e.Participant.Modalities[ModalityTypes.InstantMessage]).InstantMessageReceived += new EventHandler <MessageSentEventArgs>(ConversationTest_InstantMessageReceived);
                    ((InstantMessageModality)e.Participant.Modalities[ModalityTypes.InstantMessage]).IsTypingChanged        += new EventHandler <IsTypingChangedEventArgs>(ConversationTest_IsTypingChanged);
                }
                Conversation conversation = (Conversation)sender;

                InstantMessageModality imModality = (InstantMessageModality)conversation.Modalities[ModalityTypes.InstantMessage];
                string messageContent             = "Hello World";
                IDictionary <InstantMessageContentType, string> formattedMessage = this.GenerateFormattedMessage(messageContent);

                try
                {
                    if (imModality.CanInvoke(ModalityAction.SendInstantMessage))
                    {
                        IAsyncResult asyncResult = imModality.BeginSendMessage(
                            formattedMessage,
                            SendMessageCallback,
                            imModality);
                    }
                }
                catch (LyncClientException ex)
                {
                    txtErrors.Text = ex.Message;
                }
            }
        }
Example #8
0
        // Callback method for the BeginSendContextData method.
        public void SendContextDataCallback(IAsyncResult res)
        {
            ConversationWindow     _conversationWindow = ((Automation)res.AsyncState).EndStartConversation(res);
            InstantMessageModality instantMessage      = (InstantMessageModality)_conversationWindow.Conversation.Modalities[ModalityTypes.InstantMessage];

            instantMessage.BeginSendMessage("hello sdx - success!", SendCMessageCallback, null);
        }
        void Conversation_ParticipantAdded(object sender, ParticipantCollectionChangedEventArgs e)
        {
            // add event handlers for modalities of participants other than self participant:
            if (e.Participant.IsSelf == false)
            {
                if (((Conversation)sender).Modalities.ContainsKey(ModalityTypes.InstantMessage))
                {
                    ((InstantMessageModality)e.Participant.Modalities[ModalityTypes.InstantMessage]).InstantMessageReceived += new EventHandler <MessageSentEventArgs>(ConversationTest_InstantMessageReceived);
                    ((InstantMessageModality)e.Participant.Modalities[ModalityTypes.InstantMessage]).IsTypingChanged        += new EventHandler <IsTypingChangedEventArgs>(ConversationTest_IsTypingChanged);
                }
                Conversation conversation = (Conversation)sender;

                InstantMessageModality imModality = (InstantMessageModality)conversation.Modalities[ModalityTypes.InstantMessage];

                IDictionary <InstantMessageContentType, string> textMessage = new Dictionary <InstantMessageContentType, string>();
                textMessage.Add(InstantMessageContentType.PlainText, "Hello World");

                if (imModality.CanInvoke(ModalityAction.SendInstantMessage))
                {
                    IAsyncResult asyncResult = imModality.BeginSendMessage(
                        textMessage,
                        SendMessageCallback,
                        imModality);
                }
            }
        }
Example #10
0
        public void SendLyncMessage(string contactMail, string message)
        {
            var contact = lyncClient.ContactManager.GetContactByUri(contactMail);
            var conv    = lyncClient.ConversationManager.AddConversation();

            conv.AddParticipant(lyncClient.ContactManager.GetContactByUri(contact.Uri));

            InstantMessageModality m = conv.Modalities[ModalityTypes.InstantMessage] as InstantMessageModality;

            m.BeginSendMessage(message, null, null);
        }
Example #11
0
 //send message
 private void button2_Click(object sender, RoutedEventArgs e)
 {
     foreach (Conversation conversation in _LyncClient.ConversationManager.Conversations)
     {
         InstantMessageModality instantMessage = (InstantMessageModality)conversation.Modalities[ModalityTypes.InstantMessage];
         Dictionary <InstantMessageContentType, string> contents = new Dictionary <InstantMessageContentType, string>();
         contents.Add(InstantMessageContentType.PlainText, "http://www.google.com");
         //instantMessage.BeginSendMessage("hello sdx - success!", SendCMessageCallback, null);
         instantMessage.BeginSendMessage(contents, SendCMessageCallback, null);
     }
 }
Example #12
0
        private static void ChatRecived(object sender, MessageSentEventArgs e)
        {
            InstantMessageModality nananana = (InstantMessageModality)sender;
            // el user ees elPibe
            string elPibe = nananana.Endpoint.DisplayName.Substring(0, nananana.Endpoint.DisplayName.LastIndexOf("@"));
            // por ahora, luego habrá que separar los argumentos,
            //no mejor habria que derivar del comando cuantos y que arg lleva y preguntarlos y esas cosas que le gustan al Colo
            string elComando = e.Text;

            //loguear
            Console.WriteLine(DateTime.Now + ". " + elPibe + " dice: " + elComando);

            nananana.BeginSendMessage("Llegó, gracias " + elPibe, (ar) => { nananana.EndSendMessage(ar); }, null);

            //Executar comando y contar como va yendo y esa onda
            var elResul = Ejecuta(elPibe, elComando);

            Console.WriteLine(elResul);

            nananana.BeginSendMessage(elResul, (ar) => { nananana.EndSendMessage(ar); }, null);
        }
Example #13
0
        private void ImModality_InstantMessageReceived(object sender, MessageSentEventArgs e)
        {
            InstantMessageModality im = (InstantMessageModality)sender;

            if (!im.Participant.IsSelf)
            {
                var botConversation = directLineCLient.Conversations.NewConversationWithHttpMessagesAsync().Result.Body;

                var message = new Message();
                message.ConversationId = botConversation.ConversationId;
                message.Text           = e.Text;
                var result = directLineCLient.Conversations.PostMessageWithHttpMessagesAsync(botConversation.ConversationId, message).Result;

                var response = directLineCLient.Conversations.GetMessagesWithHttpMessagesAsync(botConversation.ConversationId).Result;

                im.BeginSendMessage(response.Body.Messages.LastOrDefault().Text, null, response.Body.Messages.LastOrDefault());
            }
        }
Example #14
0
        protected override void Execute(NativeActivityContext context)
        {
            try
            {
                string[]     arrRecepients = ReciepientList.Get(context).Split(';'); //add your recepients here
                LyncClient   lyncClient    = LyncClient.GetClient();
                Conversation conversation  = lyncClient.ConversationManager.AddConversation();

                foreach (string recepient in arrRecepients)
                {
                    conversation.AddParticipant(lyncClient.ContactManager.GetContactByUri(recepient));
                }
                InstantMessageModality imModality = conversation.Modalities[ModalityTypes.InstantMessage] as InstantMessageModality;
                string message = Message.Get(context);//use your existing notification logic here
                imModality.BeginSendMessage(message, null, null);
            }
            catch (Exception ex)
            {
            }
        }
Example #15
0
 void ConversationTest_InstantMessageReceived(object sender, MessageSentEventArgs e)
 {
     ShowNewMessage(e);
     try
     {
         if (_ConversationImModality.CanInvoke(ModalityAction.SendInstantMessage))
         {
             _ConversationImModality.BeginSendMessage(
                 "Got your message",
                 (ar) =>
             {
                 _ConversationImModality.EndSendMessage(ar);
             }
                 ,
                 null);
         }
     }
     catch (LyncClientException ex)
     {
         txtErrors.Text = ex.Message;
     }
 }
        private void BeginSearchCallback(IAsyncResult r)
        {
            object[]       asyncState = (object[])r.AsyncState;
            ContactManager cm         = (ContactManager)asyncState[0];

            try
            {
                SearchResults results = cm.EndSearch(r);
                if (results.AllResults.Count == 0)
                {
                    Console.WriteLine("No results.");
                }
                else if (results.AllResults.Count == 1)
                {
                    ContactSubscription srs     = cm.CreateSubscription();
                    Contact             contact = results.Contacts[0];
                    srs.AddContact(contact);
                    ContactInformationType[] contactInformationTypes = { ContactInformationType.Availability, ContactInformationType.ActivityId };
                    srs.Subscribe(ContactSubscriptionRefreshRate.High, contactInformationTypes);
                    _conversation = _client.ConversationManager.AddConversation();
                    _conversation.AddParticipant(contact);
                    Dictionary <InstantMessageContentType, String> messages = new Dictionary <InstantMessageContentType, String>();
                    messages.Add(InstantMessageContentType.PlainText, _message);
                    InstantMessageModality m = (InstantMessageModality)_conversation.Modalities[ModalityTypes.InstantMessage];
                    m.BeginSendMessage(messages, BeginSendMessageCallback, messages);
                }
                else
                {
                    Console.WriteLine("More than one result.");
                }
            }
            catch (SearchException se)
            {
                Console.WriteLine("Search failed: " + se.Reason.ToString());
            }
            _client.ContactManager.EndSearch(r);
        }
Example #17
0
        public static void makeMessage(int flag, InstantMessageModality insM, string add)
        {
            Conversation conv    = insM.Conversation;
            string       Message = "";
            Random       r       = new Random();

            if (flag == 0)
            {
                string[] arr = add.Split(' ');
                try
                {
                    conn.Open();
                    DataSet ds = new DataSet();
                    String  sql;
                    sql = "SELECT res FROM bot where req = '" + arr[0] + "'";

                    MySqlDataAdapter adpt = new MySqlDataAdapter(sql, conn);
                    adpt.Fill(ds, "bot");
                    try
                    {
                        Message = ds.Tables[0].Rows[r.Next(ds.Tables[0].Rows.Count)].ItemArray[0].ToString(); // res 가 2개일때 처리
                    }
                    catch
                    {
                        Message = "알 수 없는 명령어 입니다. \r\n\r\n EX) !추가 [가르칠 말] [반응할 말]";
                    }
                    conn.Close();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.StackTrace);
                    conn.Close();
                }
            }
            if (flag == 1)
            {
                int a = 17 - Convert.ToInt32(DateTime.Now.ToString("HH"));
                int b = 59 - Convert.ToInt32(DateTime.Now.ToString("mm"));
                int c = 59 - Convert.ToInt32(DateTime.Now.ToString("ss"));
                Message = "퇴근시간까지 " + a.ToString() + "시간 " + b.ToString() + "분 " + c.ToString() + "초 남았습니다.";
            }

            if (flag == 2)
            {
                Message = "1~100 을 굴려 " + r.Next(1, 100) + "가 나왔습니다.";
            }
            if (flag == 3)
            {
                string[] arr  = add.Split(' ');
                string   Carr = "";

                for (int i = 1; i < arr.Length; i++)
                {
                    Carr += arr[i] + " ";
                }

                conn.Open();
                String       sql = "INSERT INTO bot (req, res) VALUES ('" + arr[0] + "', '" + Carr + "')";
                MySqlCommand cmd = new MySqlCommand(sql, conn);
                cmd.ExecuteNonQuery();
                conn.Close();
                Message = "알림 : !" + arr[0] + " 추가 되었습니다.";
            }
            if (flag == 4)
            {
                Meal   SJ   = new Meal();
                string meal = SJ.parse(add);
                meal = meal.Replace("한식(쌀밥)", "\r\n\r\n<DIV style = 'color: green;font:bold; font-size:20p;'> 한식(쌀밥)</DIV>\r\n\r\n");
                meal = meal.Replace("한식(잡곡밥)", "\r\n\r\n<DIV style = 'color: green;font:bold; font-size:20p;'> 한식(잡곡밥)</DIV>\r\n\r\n");
                meal = meal.Replace("간편식", "\r\n\r\n<DIV style = 'color: green;font:bold; font-size:20p;'> 간편식</DIV>\r\n\r\n");
                meal = meal.Replace("해장국", "\r\n\r\n<DIV style = 'color: green;font:bold; font-size:20p;'> 해장국</DIV>\r\n\r\n");
                meal = meal.Replace("분식", "\r\n\r\n<DIV style = 'color: green;font:bold; font-size:20p;'> 분식</DIV>\r\n\r\n");
                meal = meal.Replace("건강식", "\r\n\r\n<DIV style = 'color: green;font:bold; font-size:20p;'> 건강식</DIV>\r\n\r\n");
                meal = meal.Replace("선택코너", "\r\n\r\n<DIV style = 'color: green;font:bold; font-size:20p;'> 선택코너</DIV>\r\n\r\n");
                meal = meal.Replace("일품식", "\r\n\r\n<DIV style = 'color: green;font:bold; font-size:20p;'> 일품식</DIV>\r\n\r\n");
                messageDictionary = new Dictionary <InstantMessageContentType, string>();
                messageDictionary.Add(InstantMessageContentType.Html, meal);
                goto SENDSTART;
            }

            string FormattedMessage = "<DIV style='color: green;font:bold; font-size:20p;'>" + Message + "</DIV>";

            messageDictionary = new Dictionary <InstantMessageContentType, string>();
            messageDictionary.Add(InstantMessageContentType.Html, FormattedMessage);

SENDSTART:
            insM.BeginSendMessage(messageDictionary, ar =>
            {
                try
                {
                    insM.EndSendMessage(ar);
                }
                catch (Exception ex) { }
            }, null);
        }
 /// <summary>
 /// Sends a message into the conversation.
 /// </summary>
 public void SendMessage(MessageContext context)
 {
     //sends the message
     myImModality.BeginSendMessage(context.TranslatedMessage, myImModality_OnMessageSent, context);
 }