private void RenderHeroCard(Microsoft.Bot.Connector.DirectLine.Attachment attachment) { // It seems that the Discord cannot display any other message type except text and voice. Console.WriteLine(attachment.Content.ToString()); ISocketMessageChannel channel = Program.GetDiscordSocketChannel(ChannelId); if (null != channel) { channel.SendMessageAsync(attachment.Content.ToString()); Thread.Sleep(20); } }
private static async Task SendMessageToBotAsync(string conversationId, SocketMessage msg) { if (null == msg) { return; } // Set channel object. _conversationManager[msg.Channel.Id].Channel = msg.Channel; var act = new Activity(); act.ChannelId = _theChannelName; act.From = new ChannelAccount(msg.Author.Id.ToString(), msg.Author.Username); act.Text = msg.Content; if (MessageSource.System == msg.Source) { act.Type = ActivityTypes.ConversationUpdate; } else if (MessageSource.User == msg.Source) { act.Type = ActivityTypes.Message; } act.Conversation = new ConversationAccount(); // Set group flag. if ('@' == msg.Channel.Name[0]) { act.Conversation.IsGroup = false; } else { act.Conversation.IsGroup = true; } act.Conversation.Id = conversationId; act.Conversation.Name = msg.Channel.Name; var channelData = new Newtonsoft.Json.Linq.JObject(); channelData["groupName"] = (msg.Channel as SocketTextChannel)?.Guild.Name + "#" + msg.Channel.Name; channelData["isGroup"] = act.Conversation.IsGroup; channelData["channelId"] = _theChannelName; act.ChannelData = channelData; foreach (Discord.Attachment datt in msg.Attachments) { string url = datt.Url; Microsoft.Bot.Connector.DirectLine.Attachment att = new Microsoft.Bot.Connector.DirectLine.Attachment(); // Actually, When user send a file, DiscordApp always upload it to DiscordApp media server // and then raise MessageReceived event. If you want to get binary please un-comments below code. // But usually, we only need to send media Uri. Because it will improve message transfer speed. // //HttpClient client = new HttpClient(); //using (Stream s = await client.GetStreamAsync(url)) //{ // byte[] buff = new byte[s.Length]; // s.Read(buff, 0, (int)s.Length); // att.Content = buff; //} att.ContentType = GetMediaTypeFromUri(url); att.ContentUrl = url; act.Attachments.Add(att); } Log.OutputLine(string.Format("Directing channel[{0}] activity to bot conversation[{1}] ...", msg.Channel.Id, conversationId)); var resp = await _directlineClinet.Conversations.PostActivityAsync(conversationId, act); Log.OutputLine(string.Format("Direct channel[{0}] activity to bot conversation[{1}] response {2}", msg.Channel.Id, conversationId, resp.Id)); }