Search code examples
c#azurebotframeworkskype-bots

Why I can't save and retrieve bot data in Azure Tables in Skype channel?


I've been working with bot for the lat three months, my Bot is finished in Webchannel,direct line, telegram and now I'm working on Skype channel, everything is fine except save and retrieve data from Azure Tables, I'm geting the error "Unknown activity type" in Azure portal log.

You can find my code below:

This is the main rootdialog class

using System;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
using SimpleEchoBot.Formulário;
using Microsoft.Bot.Builder.FormFlow;
using SimpleEchoBot.Serviço;
using System.Collections.Generic;
using System.Text;
using AdaptiveCards;
using System.Threading;

namespace SimpleEchoBot.Dialogs
{
  [Serializable]
  public class RootDialog : IDialog<EntidadeCliente>
  {
   private string nome;
   private string email;

   public async Task StartAsync(IDialogContext context)
   {            
    if (context.Activity.ChannelId == "telegram")
    {                 
     context.Wait(TelegramAsync);
    }
    else if (context.Activity.ChannelId == "skype")
    {
     context.Wait(SkypeAsync);
    }
    else
    { 
     context.Wait(MessageReceivedAsync);
    }
   }
   private async Task SkypeAsync(IDialogContext context, 
   IAwaitable<IMessageActivity> result)
   {
    context.Call(new NomeDialog(), NomeDialogResumeAfter);            
   }
   private async Task NomeDialogResumeAfter(IDialogContext 
   context,IAwaitable<string> result)
   {
    try
    {
     nome = await result;
     BuscarDadosAzure buscarDadosAzure = new BuscarDadosAzure();
     EntidadeCliente cliente = new EntidadeCliente();
     GravarDadosAzure gravarDadosAzure = new GravarDadosAzure();
     cliente = buscarDadosAzure.PesquisarAtendimento(nome);
     gravarDadosAzure.GravarDados(context, cliente);
     await context.PostAsync($"Agora que já nos conhecemos { nome }, quais 
     seriam as informações poderia lhe ajudar?");
     context.Wait(MessageReceivedAsync);
    }
    catch (TooManyAttemptsException)
    {
     await context.PostAsync("Me desculpe, não consegui registrar o seu 
     nome, agradecemos a sua visita.");
     context.EndConversation(EndOfConversationCodes.UserCancelled);
    }
  }
}

This class save the data into Azure

public class GravarDadosAzure
{        
 public EntidadeCliente GravarDados(IDialogContext context, 
 EntidadeCliente cliente)
 {    
  CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
  CloudConfigurationManager.GetSetting("StorageConnectionString2"));    
  CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

  Microsoft.WindowsAzure.Storage.Table.CloudTable table = 
  tableClient.GetTableReference("Usuario");
  TableOperation insertOperation = 
  TableOperation.InsertOrReplace(cliente);
  table.Execute(insertOperation);

  return cliente;
}

This Class retrieve data from Azure.

public EntidadeCliente PesquisarAtendimento(EntidadeCliente cliente, 
[Optional] string 
ConversationId)
{    
 CloudStorageAccount storageAccount = CloudStorageAccount.Parse(                
 CloudConfigurationManager.GetSetting("StorageConnectionString2"));    
 CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
 CloudTable table = tableClient.GetTableReference("Usuario");            
 if (ConversationId == null)
 {
  TableQuery<EntidadeCliente> query = new TableQuery<EntidadeCliente> 
  ().Where(TableQuery.GenerateFilterCondition("Nome", 
  QueryComparisons.Equal, cliente.nome));                
  BuscarEntidade(table, cliente, query);
 }
 else
 {
  TableQuery<EntidadeCliente> query = new TableQuery<EntidadeCliente> 
  ().Where(TableQuery.GenerateFilterCondition("ConversationId", 
  QueryComparisons.Equal, ConversationId));
  BuscarEntidade(table, cliente, query);
 }           
  return cliente;
}

Solution

  • I have found the solution, I was using some values in Skype in the same that I use in directline, and that value was null in Skype that's why Azure didn't accept insert operation.

    I think my key (context.Activity.ChannelId + empty value) generated the error message "Unknown activity type" into Azure portal log.