예제 #1
0
파일: Messenger.cs 프로젝트: androck22/Bot
 private async Task SendTextWithKeyBoard(Conversation chat, string text, InlineKeyboardMarkup keyboard)
 {
     await botClient.SendTextMessageAsync(chatId : chat.GetId(), text : text, replyMarkup : keyboard);
 }
예제 #2
0
파일: Messenger.cs 프로젝트: androck22/Bot
 private async Task SendText(Conversation chat, string text)
 {
     await botClient.SendTextMessageAsync(chatId : chat.GetId(), text : text);
 }
예제 #3
0
 private async Task SendMessage(Conversation chat)
 {
     await messenger.MakeAnswer(chat);
 }
예제 #4
0
        public static async Task <HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            log.Info($"Webhook was triggered!");

            // Initialize the azure bot
            using (new AzureFunctionsResolveAssembly())
                using (BotService.Initialize())
                {
                    // Deserialize the incoming activity
                    string jsonContent = await req.Content.ReadAsStringAsync();

                    var activity = JsonConvert.DeserializeObject <Activity>(jsonContent);

                    // authenticate incoming request and add activity.ServiceUrl to MicrosoftAppCredentials.TrustedHostNames
                    // if request is authenticated
                    if (!await BotService.Authenticator.TryAuthenticateAsync(req, new[] { activity }, CancellationToken.None))
                    {
                        return(BotAuthenticator.GenerateUnauthorizedResponse(req));
                    }

                    if (activity != null)
                    {
                        // one of these will have an interface and process it
                        switch (activity.GetActivityType())
                        {
                        case ActivityTypes.Message:
                            //await Translate(activity);
                            await Conversation.SendAsync(activity, () => new EchoLuisDialog());

                            break;

                        case ActivityTypes.ConversationUpdate:
                            var client = new ConnectorClient(new Uri(activity.ServiceUrl));
                            IConversationUpdateActivity update = activity;
                            if (update.MembersAdded.Any())
                            {
                                var reply      = activity.CreateReply();
                                var newMembers = update.MembersAdded?.Where(t => t.Id != activity.Recipient.Id);
                                foreach (var newMember in newMembers)
                                {
                                    reply.Text = "Welcome";
                                    if (!string.IsNullOrEmpty(newMember.Name))
                                    {
                                        reply.Text += $" {newMember.Name}";
                                    }
                                    reply.Text += "!";
                                    await client.Conversations.ReplyToActivityAsync(reply);
                                }
                            }
                            break;

                        case ActivityTypes.ContactRelationUpdate:
                        case ActivityTypes.Typing:
                        case ActivityTypes.DeleteUserData:
                        case ActivityTypes.Ping:
                        default:
                            log.Error($"Unknown activity type ignored: {activity.GetActivityType()}");
                            break;
                        }
                    }
                    return(req.CreateResponse(HttpStatusCode.Accepted));
                }
        }
예제 #5
0
파일: Program.cs 프로젝트: freebe1/SkypeBot
        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);
        }