Example #1
0
        static void Main(string[] args)
        {
            // создать клиента бота на основе токена, который даёт Botfather
            // при создании бота
            Bot = new TelegramBotClient("628819908:AAFWj7Qd2ip3EnUBv3PQtDNEigzLTpz7tBk");
            AIConfiguration config = new AIConfiguration("6ff45427701948208179247e794f1af6", SupportedLanguage.Russian);

            apiAi = new ApiAi(config);


            // подписка на событие -- когда будет приходить сообщение,
            // будет вызываться метод BotOnMessageReceived
            Bot.OnMessage += BotOnMessageReceived;

            //
            Bot.OnCallbackQuery += BotOnCallbackQueryReceived;

            // выдаст имя бота
            var me = Bot.GetMeAsync().Result;

            Console.WriteLine(me.FirstName);

            // начать получение сообщений
            Bot.StartReceiving();

            Console.ReadKey(true);

            Bot.StopReceiving();
        }
Example #2
0
        static void Main(string[] args)
        {
            var    config = new AIConfiguration(SUBSCRIPTION_KEY, ACCESS_TOKEN, SupportedLanguage.English);
            var    apiAi  = new ApiAi(config);
            string rl     = "";

            while (rl == "")
            {
                var sw       = Stopwatch.StartNew();
                var response = apiAi.TextRequest("hello");
                sw.Stop();

                Console.WriteLine("api sync answer: {0}, time: {1} ms", response.Result.Action, sw.ElapsedMilliseconds.ToString());

                sw = Stopwatch.StartNew();
                apiAi.TextRequestStart("hello");
                System.Threading.Thread.Sleep(250);
                response = apiAi.TextRequestFinish();
                sw.Stop();

                Console.WriteLine("api async answer: {0}, time: {1} ms", response.Result.Action, sw.ElapsedMilliseconds.ToString());


                rl = Console.ReadLine();
            }
        }
Example #3
0
        private async void InstantMessageReceived(object sender, MessageSentEventArgs e)
        {
            var    text = e.Text.Replace(Environment.NewLine, string.Empty);
            string myRemoteParticipantUri = (sender as InstantMessageModality).Endpoint.Uri.Replace("sip:", string.Empty);
            var    username_string        = (sender as InstantMessageModality).Participant.Contact.GetContactInformation(ContactInformationType.DisplayName);;

            try
            {
                //LogMessage(myRemoteParticipantUri, text);
                string strResult = "";
                apiAi = Get_apiai_object_from_username(myRemoteParticipantUri);

                List <AIContext> aicontext = new List <AIContext>();
                AIContext        user_info = new AIContext();
                user_info.Name = "skype_username="******"speech"].ToString();
                strResult = ret_text;

                (sender as InstantMessageModality).BeginSendMessage(strResult, null, null);
            }
            catch (Exception ex)
            {
                //LogMessage(myRemoteParticipantUri, ex.Message);
            }
        }
Example #4
0
        public App()
        {
            Microsoft.ApplicationInsights.WindowsAppInitializer.InitializeAsync(
                Microsoft.ApplicationInsights.WindowsCollectors.Metadata |
                Microsoft.ApplicationInsights.WindowsCollectors.Session);

            this.InitializeComponent();

            //Create Database File
            if (!CheckFileExists("POS.sqlite").Result)
            {
                using (var db = new SQLiteConnection(DB_PATH))
                {
                    db.CreateTable <Categorys>();
                    db.CreateTable <Product>();
                    db.CreateTable <Member>();
                    db.CreateTable <Sale>();
                    db.CreateTable <MemberTime>();
                    db.CreateTable <SaleSearch>();
                    db.CreateTable <SaleHistory>();
                }
            }

            this.Suspending += OnSuspending;
            this.Resuming   += OnResuming;

            //Access Ai, Language is English
            var config = new AIConfiguration("6bcfd8fcf822482e935475852b97c02d",
                                             SupportedLanguage.English);

            AIService = AIService.CreateService(config);

            apiAi = new ApiAi(config);
            apiAi.DataService.PersistSessionId();
        }
Example #5
0
        private void OnTextMessaged(string agentId, WebhookMessage <WebhookTextMessage> message)
        {
            Console.WriteLine($"OnTextMessaged: {message.Message.Text}");

            var ai    = new ApiAi();
            var agent = ai.LoadAgent(agentId);

            ai.AiConfig = new AIConfiguration(agent.ClientAccessToken, SupportedLanguage.English)
            {
                AgentId = agentId
            };
            ai.AiConfig.SessionId = message.Sender.Id;
            var aiResponse = ai.TextRequest(new AIRequest {
                Query = new String[] { message.Message.Text }
            });

            var dc     = new DefaultDataContextLoader().GetDefaultDc();
            var config = dc.Table <AgentIntegration>().FirstOrDefault(x => x.AgentId == agentId && x.Platform == "Facebook Messenger");

            SendTextMessage(config.AccessToken, new WebhookMessage <WebhookTextMessage>
            {
                Recipient = message.Sender.ToObject <WebhookMessageRecipient>(),
                Message   = new WebhookTextMessage
                {
                    Text = String.IsNullOrEmpty(aiResponse.Result.Fulfillment.Speech) ? aiResponse.Result.Action : aiResponse.Result.Fulfillment.Speech
                }
            });
        }
Example #6
0
        static void Main(string[] args)
        {
            Console.Title = "Console-ApiAi-Bot";

            for (;;)
            {
                Console.Clear();
                Console.Write("Введите запрос: ");

                var responseString = Console.ReadLine();

                if (String.IsNullOrWhiteSpace(responseString))
                {
                    Console.WriteLine("\nНапишите, пожалуйста, Ваш запрос!");
                    Console.ReadLine();
                    continue;
                }

                // Конфигурация агента Api.ai
                var config = new AIConfiguration(ClientAccessToken, SupportedLanguage.Russian);
                var apiAi  = new ApiAi(config);

                // Ответ
                var response = apiAi.TextRequest(responseString);
                if (response == null)
                {
                    continue;
                }

                Console.WriteLine("Ответ: {0}", response.Result.Fulfillment.Speech);

                Console.ReadLine();
            }
        }
Example #7
0
        void Initialization()
        {
            web = new WebClient();
            AIConfiguration aiConfig = new AIConfiguration(dialogeFlowAPI, SupportedLanguage.Russian);

            ai = new ApiAi(aiConfig);
        }
 public TextHandler(TelegramBotClient bot, KeyboardFactory keyboardFactory, ApiAi ai)
 {
     _bot             = bot;
     _keyboardFactory = keyboardFactory;
     _ai     = ai;
     _logger = new Logger(this);
 }
Example #9
0
        public void Initialise()
        {
            var sessionId = Guid.NewGuid().ToString();
            var config    = new AIConfiguration(Bot.DialogFlowAccessToken, SupportedLanguage.English);

            config.SessionId = sessionId;
            this.apiAi       = new ApiAi(config);
        }
Example #10
0
        public static string MessageAi(string messageText)
        {
            Apiai = new ApiAi(config);
            var    response = Apiai.TextRequest(messageText);
            string message  = response.Result.Fulfillment.Speech;

            return(message);
        }
        public SmallTalkService(SmallTalkSettings smallTalkSettings, TelegramBotSettings telegramBotSettings)
        {
            var config = new AIConfiguration(smallTalkSettings.Token, SupportedLanguage.Russian);

            ApiAi = new ApiAi(config);

            TelegramBotClient = new TelegramBotClient(telegramBotSettings.Token);
        }
Example #12
0
        public GoogleNLP(string ClientToken, string Language = "Spanish")
        {
            SupportedLanguage supLang = ApiAiSDK.SupportedLanguage.FromLanguageTag(Language);
            var config = new AIConfiguration(ClientToken, supLang);

            apiAI       = new ApiAi(config);
            IsConnected = true;
        }
Example #13
0
        public AIResponse postApiAi(string messageText)
        {
            var config = new AIConfiguration(apiAiToken,
                                             SupportedLanguage.Spanish);
            ApiAi apiAi    = new ApiAi(config);
            var   response = apiAi.TextRequest(messageText);

            return(response);
        }
Example #14
0
        private static ApiAi CreateDialogFlowClient(string sessionId)
        {
            var configuration = new AIConfiguration(DialogFlowAccessToken, SupportedLanguage.English);

            configuration.SessionId = sessionId;
            var apiAi = new ApiAi(configuration);

            return(apiAi);
        }
Example #15
0
        /// <summary>
        /// Инициализация бота и ИИ
        /// </summary>
        public static void BotInitialization()
        {
            string token = File.ReadAllText(@"C:\Users\Sergey\Desktop\Программирование\MyToken.txt");

            bot = new TelegramBotClient(token);                                                                          // инициализация бота

            AIConfiguration config = new AIConfiguration("6dff9142fdb3499c937673175c0c52b6", SupportedLanguage.Russian); // конфигурация ИИ

            apiAi = new ApiAi(config);                                                                                   // инициализация ИИ
        }
Example #16
0
        public static string GetDialogFlowAnswer(string message)
        {
            var config = new AIConfiguration("564e2b6d00424a6ab05ba53cd57b585c", SupportedLanguage.English);

            apiAi = new ApiAi(config);

            var responseString = apiAi.TextRequest(message);

            return(responseString.Result.Fulfillment.Speech);
        }
Example #17
0
        public String postApiAi(string messageText)
        {
            var config = new AIConfiguration(apiAiToken,
                                             SupportedLanguage.English);

            apiAi = new ApiAi(config);
            var response = apiAi.TextRequest(messageText);

            return(response.Result.Fulfillment.Speech);
        }
Example #18
0
        public string Preguntar(string texto)
        {
            var config = new AIConfiguration("21958005f5f248369e6c263abe7d1572 ", SupportedLanguage.Spanish);

            apiAi = new ApiAi(config);
            var    response  = apiAi.TextRequest(texto);
            string Respuesta = response.Result.Fulfillment.Speech;

            return(Respuesta);
        }
Example #19
0
        public string Response()
        {
            var config = new AIConfiguration("c3e6138548984161bd501920dc0ea0d5", SupportedLanguage.Dutch);

            apiAi = new ApiAi(config);

            var response = apiAi.TextRequest("Ik ben opzoek naar het jaarrooster.");

            return(response.Result.Fulfillment.Speech);
        }
        public ActionResult SendTextMessage(String text)
        {
            if (apiAi == null)
            {
                var config = new AIConfiguration("2fe096a4e267427c9d3443810a7b82e2", SupportedLanguage.English);
                apiAi = new ApiAi(config);
            }

            RequestExtras re = new RequestExtras();

            re.Contexts = (List <AIContext>)HttpContext.Session["Contexts"];

            AIResponse response = apiAi.TextRequest(text, re);

            if (response.IsError)
            {
                Console.Out.Write("There is an error");

                return(Json(new
                {
                    Response = "error"
                }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                Console.Out.Write(response.Result.Fulfillment.Speech);

                if (response.Result.Contexts != null)
                {
                    contexts = new List <AIContext>();

                    foreach (var aoc in response.Result.Contexts.ToList())
                    {
                        AIContext ac = new AIContext();

                        ac.Lifespan   = aoc.Lifespan;
                        ac.Name       = aoc.Name;
                        ac.Parameters = aoc.Parameters.ToDictionary(k => k.Key, k => k.Value.ToString());;

                        contexts.Add(ac);
                    }
                }
                else
                {
                    contexts = null;
                }

                HttpContext.Session["Contexts"] = contexts;

                return(Json(new
                {
                    Response = response.Result.Fulfillment.Speech
                }, JsonRequestBehavior.AllowGet));
            }
        }
Example #21
0
        static void Main(string[] args)
        {
            //System.Console.WriteLine("here1");
            //mysqlpiContext mc = new mysqlpiContext();


            //buisness b = new buisness();
            //b.name = "test final";

            /*mc.buisnesses.Add(b);
             * mc.SaveChanges();*/
            //IServiceBusiness service = new ServiceBusiness();
            //service.Add(b);
            //service.commit();
            //System.Console.WriteLine("here2");
            //System.Console.Read();

            ApiAi ai;
            var   config = new AIConfiguration("2b4219f782904d6a996efcc54b5742fe", SupportedLanguage.English);

            ai = new ApiAi(config);

            while (true)
            {
                System.Console.WriteLine("Say something");
                string input = System.Console.ReadLine();
                if (input == "0")
                {
                    break;
                }
                var response = ai.TextRequest(input);
                System.Console.WriteLine("========Context Debug============");
                foreach (var context in response.Result.Contexts)
                {
                    System.Console.WriteLine("context : " + context.Name);
                    System.Console.WriteLine("Parameters : {");

                    foreach (KeyValuePair <string, object> pair in context.Parameters)
                    {
                        System.Console.WriteLine(pair.Key);
                        System.Console.WriteLine(pair.Value);
                    }
                }
                System.Console.WriteLine("}\n=========End Debug=======");
                System.Console.WriteLine(response.Result.Fulfillment.Speech);
                if (response.Result.GetStringParameter("subject") != "" &&
                    response.Result.GetStringParameter("description") != "")
                {
                    System.Console.WriteLine("subject : " + response.Result.GetStringParameter("subject"));
                    System.Console.WriteLine("description : " + response.Result.GetStringParameter("description"));
                    break;
                }
            }
            System.Console.ReadLine();
        }
Example #22
0
        public void Initialize(AIConfiguration config)
        {
            this.config = config;
            apiAi       = new ApiAi(this.config);
#if UNITY_ANDROID
            if (Application.platform == RuntimePlatform.Android)
            {
                InitializeAndroid();
            }
#endif
        }
Example #23
0
        internal static string API_Connection_Action(string text)
        {
            ApiAi api;

            var AIconfiguration = new AIConfiguration(Constants.APIAI_SUBSCRIPTION_ID, SupportedLanguage.English);

            api = new ApiAi(config: AIconfiguration);
            var response = api.TextRequest(text);

            return(response.Result.Action.ToString());
        }
Example #24
0
        public List <ValidateUser> ValidateUser(string sUserName, string sPassword)
        {
            var config = new AIConfiguration(ACCESS_TOKEN, SupportedLanguage.English);

            var apiAi = new ApiAi(config);

            var response = apiAi.TextRequest("hh");
            List <ValidateUser> objvalidate = new List <ValidateUser>();

            return(objvalidate.ToList());
        }
Example #25
0
        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <object> result)
        {
            var activity = await result as Activity;
            var config   = new AIConfiguration("6a867e192476428b8df2fab998464b57", SupportedLanguage.English);
            var apiAi    = new ApiAi(config);
            var response = apiAi.TextRequest(activity.Text);
            // return our reply to the user
            await context.PostAsync($"{response.Result.Fulfillment.Speech}");

            context.Wait(MessageReceivedAsync);
        }
Example #26
0
        public void VoiceRequestTest()
        {
            var config = new AIConfiguration(SUBSCRIPTION_KEY, ACCESS_TOKEN, SupportedLanguage.English);

            var apiAi  = new ApiAi(config);
            var stream = ReadFileFromResource("ApiAiSDK.Tests.TestData.what_is_your_name.raw");

            var response = apiAi.VoiceRequest(stream);

            Assert.IsNotNull(response);
            Assert.AreEqual("what is your name", response.Result.ResolvedQuery);
        }
Example #27
0
        public void TextRequestTest()
        {
            var config = new AIConfiguration(SUBSCRIPTION_KEY, ACCESS_TOKEN, SupportedLanguage.English);

            var apiAi = new ApiAi(config);

            var response = apiAi.TextRequest("hello");

            Assert.IsNotNull(response);
            Assert.AreEqual("greeting", response.Result.Action);
            Assert.AreEqual("Hi! How are you?", response.Result.Fulfillment.Speech);
        }
Example #28
0
		public void VoiceRequestTest()
		{
			var config = new AIConfiguration(SUBSCRIPTION_KEY, ACCESS_TOKEN, SupportedLanguage.English);

			var apiAi = new ApiAi(config);
			var stream = ReadFileFromResource("ApiAiSDK.Tests.TestData.what_is_your_name.raw");

			var response = apiAi.VoiceRequest(stream);

			Assert.IsNotNull(response);
			Assert.AreEqual("what is your name", response.Result.ResolvedQuery);
		}
Example #29
0
		public void TextRequestTest()
		{
			var config = new AIConfiguration(SUBSCRIPTION_KEY, ACCESS_TOKEN, SupportedLanguage.English);

			var apiAi = new ApiAi(config);

			var response = apiAi.TextRequest("hello");

			Assert.IsNotNull(response);
			Assert.AreEqual("greeting", response.Result.Action);
            Assert.AreEqual("Hi! How are you?", response.Result.Fulfillment.Speech);
		}
Example #30
0
        internal static string API_Response(string text)
        {
            ApiAi apiAi;

            var config = new AIConfiguration(Constants.APIAI_SUBSCRIPTION_ID, SupportedLanguage.English);

            apiAi = new ApiAi(config);

            var resposne = apiAi.TextRequest(text);

            return(resposne.Result.Fulfillment.Speech);
        }
        public MainWindow()
        {
            InitializeComponent();

            var config = new AIConfiguration("19702fe30641436e9f364e493cebfb0d", SupportedLanguage.English);

            apiAi = new ApiAi(config);

            img_record.Visibility = Visibility.Visible;
            ellipse.Visibility    = Visibility.Hidden;
            lbl_status.Content    = "Нажмите кнопку";
        }
Example #32
0
        /// <summary>
        /// Конструктор по умолчанию
        /// </summary>
        internal VKontakteBot()
        {
            InitSessionAsync();
            // Инициализация DialogFlow
            var config = new AIConfiguration(Program.Cfg.AIToken, SupportedLanguage.Russian);

            ai             = new ApiAi(config);
            timer          = new System.Timers.Timer(1000 * Program.Cfg.Timer);
            timer.Elapsed += NoAction_Timer;
            timer.Elapsed += LessonWarning;
            timer.Enabled  = true;
        }