Beispiel #1
0
    private async Task CreateSession()
    {
        // Create client
        _sessionsClient = await SessionsClient.CreateAsync();

        // Initialize request argument(s)
        _sessionName = new SessionName(_projectId, _userID);
    }
Beispiel #2
0
        private async Task CreateSession()
        {
            // Create client
            sessionsClient = await SessionsClient.CreateAsync();

            // Initialize request argument(s)
            sessionName = new SessionName(settings.DialogFlowProject, userID);
        }
        /// <summary>Snippet for DetectIntentAsync</summary>
        public async Task DetectIntentAsync()
        {
            // Snippet: DetectIntentAsync(string, QueryInput, CallSettings)
            // Additional: DetectIntentAsync(string, QueryInput, CancellationToken)
            // Create client
            SessionsClient sessionsClient = await SessionsClient.CreateAsync();

            // Initialize request argument(s)
            string     session    = "projects/[PROJECT]/locations/[LOCATION]/agent/sessions/[SESSION]";
            QueryInput queryInput = new QueryInput();
            // Make the request
            DetectIntentResponse response = await sessionsClient.DetectIntentAsync(session, queryInput);

            // End snippet
        }
        /// <summary>Snippet for DetectIntentAsync</summary>
        public async Task DetectIntentResourceNamesAsync()
        {
            // Snippet: DetectIntentAsync(SessionName, QueryInput, CallSettings)
            // Additional: DetectIntentAsync(SessionName, QueryInput, CancellationToken)
            // Create client
            SessionsClient sessionsClient = await SessionsClient.CreateAsync();

            // Initialize request argument(s)
            SessionName session    = SessionName.FromProjectLocationSession("[PROJECT]", "[LOCATION]", "[SESSION]");
            QueryInput  queryInput = new QueryInput();
            // Make the request
            DetectIntentResponse response = await sessionsClient.DetectIntentAsync(session, queryInput);

            // End snippet
        }
        public async Task <QueryResult> VerificarIntent(string chatID, string message)
        {
            _sessionsClient = await SessionsClient.CreateAsync();

            _sessionName = new SessionName(chatbottelegramdio.project_id, chatID);

            QueryInput queryInput = new QueryInput();
            var        queryText  = new TextInput();

            queryText.Text         = message;
            queryText.LanguageCode = "pt-BR";
            queryInput.Text        = queryText;

            DetectIntentResponse response = await _sessionsClient.DetectIntentAsync(_sessionName, queryInput);

            return(response.QueryResult);
        }
        /// <summary>Snippet for DetectIntentAsync</summary>
        public async Task DetectIntentAsync_RequestObject()
        {
            // Snippet: DetectIntentAsync(DetectIntentRequest,CallSettings)
            // Additional: DetectIntentAsync(DetectIntentRequest,CancellationToken)
            // Create client
            SessionsClient sessionsClient = await SessionsClient.CreateAsync();

            // Initialize request argument(s)
            DetectIntentRequest request = new DetectIntentRequest
            {
                SessionAsSessionName = new SessionName("[PROJECT]", "[SESSION]"),
                QueryInput           = new QueryInput(),
            };
            // Make the request
            DetectIntentResponse response = await sessionsClient.DetectIntentAsync(request);

            // End snippet
        }
        /// <summary>Snippet for FulfillIntentAsync</summary>
        public async Task FulfillIntentRequestObjectAsync()
        {
            // Snippet: FulfillIntentAsync(FulfillIntentRequest, CallSettings)
            // Additional: FulfillIntentAsync(FulfillIntentRequest, CancellationToken)
            // Create client
            SessionsClient sessionsClient = await SessionsClient.CreateAsync();

            // Initialize request argument(s)
            FulfillIntentRequest request = new FulfillIntentRequest
            {
                MatchIntentRequest = new MatchIntentRequest(),
                Match             = new Match(),
                OutputAudioConfig = new OutputAudioConfig(),
            };
            // Make the request
            FulfillIntentResponse response = await sessionsClient.FulfillIntentAsync(request);

            // End snippet
        }
        /// <summary>Snippet for MatchIntentAsync</summary>
        public async Task MatchIntentRequestObjectAsync()
        {
            // Snippet: MatchIntentAsync(MatchIntentRequest, CallSettings)
            // Additional: MatchIntentAsync(MatchIntentRequest, CancellationToken)
            // Create client
            SessionsClient sessionsClient = await SessionsClient.CreateAsync();

            // Initialize request argument(s)
            MatchIntentRequest request = new MatchIntentRequest
            {
                SessionAsSessionName = SessionName.FromProjectLocationAgentSession("[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]"),
                QueryParams          = new QueryParameters(),
                QueryInput           = new QueryInput(),
            };
            // Make the request
            MatchIntentResponse response = await sessionsClient.MatchIntentAsync(request);

            // End snippet
        }
Beispiel #9
0
        /// <summary>Snippet for DetectIntentAsync</summary>
        public async Task DetectIntentRequestObjectAsync()
        {
            // Snippet: DetectIntentAsync(DetectIntentRequest, CallSettings)
            // Additional: DetectIntentAsync(DetectIntentRequest, CancellationToken)
            // Create client
            SessionsClient sessionsClient = await SessionsClient.CreateAsync();

            // Initialize request argument(s)
            DetectIntentRequest request = new DetectIntentRequest
            {
                SessionAsSessionName = SessionName.FromProjectLocationSession("[PROJECT]", "[LOCATION]", "[SESSION]"),
                QueryParams          = new QueryParameters(),
                QueryInput           = new QueryInput(),
                OutputAudioConfig    = new OutputAudioConfig(),
                InputAudio           = ByteString.Empty,
            };
            // Make the request
            DetectIntentResponse response = await sessionsClient.DetectIntentAsync(request);

            // End snippet
        }
Beispiel #10
0
        public async Task HandleUserMessageAsync(ReceiveMessageFromUserCallback callback)
        {
            var user = await _userDataStore.FindAsync(x => x.ViberId == callback.Sender.Id);

            if (user == null)
            {
                var entity = ViberUserFactory.ToEntity(callback);

                await _userDataStore.CreateAsync(entity).ConfigureAwait(false);

                await _userDataStore.SaveAsync().ConfigureAwait(false);
            }

            await SaveUserMessageAsync(callback);

            var client = await SessionsClient.CreateAsync();

            var response = await client.DetectIntentAsync(
                session : SessionName.FromProjectSession("viber-bot-jexkor", user.SessionId),
                queryInput : new QueryInput
            {
                Text = new TextInput
                {
                    Text         = callback.Message.Text,
                    LanguageCode = "uk-UA"
                }
            }
                );

            await _dialogflowResultDataStore.CreateAsync(new DialogflowResultEntity
            {
                Request  = callback.Message.Text,
                Response = response.QueryResult.FulfillmentText
            });

            await _dialogflowResultDataStore.SaveAsync();

            await _viberRestClient.SendMessage(
                $"{response.QueryResult.FulfillmentText}", callback.Sender.Id);
        }
Beispiel #11
0
        static async Task HandleUpdateAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken)
        {
            if (update.Type == UpdateType.Message && update.Message != null && update.Message.Type == MessageType.Text)
            {
                long   chatId      = update.Message.Chat.Id;
                string messageText = update.Message.Text;
                if (messageText == "/start")
                {
                    string menu = "/start - запуск\n/inline - меню\n/keyboard - сообщения\n/clearkeyboard - убрать кнопки";
                    await botClient.SendTextMessageAsync(chatId, menu, cancellationToken : cancellationToken);
                }
                else if (messageText == "/inline")
                {
                    InlineKeyboardMarkup inlineKeyboard = new InlineKeyboardMarkup(new[]
                    {
                        new[]
                        {
                            InlineKeyboardButton.WithUrl("VK", "https://vk.com/mishanya167"),
                            InlineKeyboardButton.WithUrl("LinkedIn", "https://www.linkedin.com/in/%D0%BC%D0%B8%D1%85%D0%B0%D0%B8%D0%BB-%D0%BA%D0%BE%D0%B2%D0%B0%D0%BB%D1%91%D0%B2-79637b164/")
                        },
                        new[]
                        {
                            InlineKeyboardButton.WithCallbackData("Дата и время", "DateTime"),
                            InlineKeyboardButton.WithCallbackData("Картинка", "Photo")
                        }
                    });
                    await botClient.SendTextMessageAsync(chatId, "Выберите пункт меню: ", replyMarkup : inlineKeyboard, cancellationToken : cancellationToken);
                }
                else if (messageText == "/keyboard")
                {
                    ReplyKeyboardMarkup replayKeyBoard = new ReplyKeyboardMarkup(new[]
                    {
                        new[]
                        {
                            new KeyboardButton("Привет"),
                            new KeyboardButton("Как дела?")
                        },
                        new[]
                        {
                            KeyboardButton.WithRequestContact("Контакт"),
                            KeyboardButton.WithRequestLocation("Геолокация")
                        }
                    });
                    await botClient.SendTextMessageAsync(chatId, "Выберите сообщение.", replyMarkup : replayKeyBoard, cancellationToken : cancellationToken);
                }
                else if (messageText == "/clearkeyboard")
                {
                    await botClient.SendTextMessageAsync(chatId, "Кнопки убраны.", replyMarkup : new ReplyKeyboardRemove(), cancellationToken : cancellationToken);
                }
                else
                {
                    SessionsClient sessionsClient = await SessionsClient.CreateAsync();

                    SessionName sessionName = new SessionName("small-talk-srqi", Guid.NewGuid().ToString());
                    QueryInput  queryInput  = new QueryInput
                    {
                        Text = new TextInput
                        {
                            Text         = messageText,
                            LanguageCode = "ru-Ru"
                        }
                    };
                    DetectIntentResponse response = await sessionsClient.DetectIntentAsync(sessionName, queryInput);

                    if (response.QueryResult.FulfillmentMessages.Count > 0)
                    {
                        await botClient.SendTextMessageAsync(chatId, response.QueryResult.FulfillmentText, cancellationToken : cancellationToken);
                    }
                    else
                    {
                        await botClient.SendTextMessageAsync(chatId, "Прости, я тебя не понимаю.", cancellationToken : cancellationToken);
                    }
                }
            }
            if (update.Type == UpdateType.CallbackQuery && update.CallbackQuery.Message != null)
            {
                string data = update.CallbackQuery.Data;
                if (data == "DateTime")
                {
                    await botClient.AnswerCallbackQueryAsync(update.CallbackQuery.Id, DateTime.Now.ToString(), cancellationToken : cancellationToken);
                }
                if (data == "Photo")
                {
                    await botClient.SendPhotoAsync(update.CallbackQuery.Message.Chat.Id, "https://big-rostov.ru/wp-content/uploads/2021/04/i-7-1.jpg", cancellationToken : cancellationToken);
                }
            }
        }