Beispiel #1
0
        public async void SetupAsync()
        {
            Log.LogMessage("Starting up Kik bot");
            var kikApi = new ConfigurationService().GetConfig("KikApiKey");

            _kikHttp = new KikHttp("https://api.kik.com/v1", kikApi);
            string webhookUrl = "";

            try
            {
                webhookUrl = _webhookService.StartWebhookService();
            } catch (Exception e)
            {
                Log.LogMessage("There was a critical error starting up the webhook service: " + e.Message, LogType.Error, e.StackTrace);
                throw e;
            }

            var kikConfig = new KikConfigDataObject
            {
                webhook  = webhookUrl,
                features = new KikFeaturesDataObject()
            };

            Log.LogMessage("Sending config to KIK");
            try
            {
                await KikMethods.SendConfigAsync(_kikHttp, kikConfig);

                Log.LogMessage("KIK bot setup and ready!");
            } catch (Exception e)
            {
                Log.LogMessage("There was a critical error sending initial config to KIK: " + e.Message, LogType.Error, e.StackTrace);
            }
        }
Beispiel #2
0
        public async Task ProcessMessage(KikGenericRecieveMessageDataObject kikGenericMessage)
        {
            string messageBody = "";

            if (kikGenericMessage is KikMessageDataObject message)
            {
                if (message.body != null)
                {
                    messageBody = message.body;
                }
            }

            var playerState = _playerController.GetPlayerByKikChannel(kikGenericMessage.chatId);

            if (playerState == null)
            {
                _reporter.ReportMessage("The bot was started in a new chat, with username: " + kikGenericMessage.from);
                playerState = _accountController.CreateNewKikAccount(kikGenericMessage.chatId, kikGenericMessage.from);
            }

            var executionResult = _gameExecutor.ProcessNewMessage(messageBody, new PlayerState {
                player = playerState
            });

            if (executionResult != null)
            {
                var batchesToSend = BuildResponses(executionResult, kikGenericMessage.chatId, kikGenericMessage.from);
                foreach (var batch in batchesToSend)
                {
                    await KikMethods.SendMessageAsync(KikService._kikHttp, batch);
                }
            }
        }
Beispiel #3
0
 public async Task ProcessInvalidInput(KikGenericRecieveMessageDataObject kikGenericMessage)
 {
     await KikMethods.SendMessageAsync(KikService._kikHttp, new KikMessagesSendDataObject {
         messages = new List <KikGenericSendMessageDataObject>
         {
             new KikMessageSendWithoutKeyboardDataObject
             {
                 body   = "That is not a valid input! Please use the suggested response buttons or type in your reply.",
                 chatId = kikGenericMessage.chatId,
                 to     = kikGenericMessage.from,
                 type   = "text",
             }
         }
     });
 }