Teams bot: Updated message with a Card not properly displayed until chat is refreshed - microsoft-teams

I have a Teams bot running with node js. I can response with a Text message or a Card to an incoming message, and I can update a previously sent message with a new Text Message.
But I have a problem when I update a message with a Card. It is not displayed properly, I see this in the chat:
<URIObject type="SWIFT.1" url_thumbnail="https://urlp.asm.skype.com/v1/url/content?url=https://neu1-urlp.secure.skypeassets.com/static/card-128x128.png">Card - access it on https://go.skype.com/cards.unsupported. <Title>Card</Title><Swift b64="eyJhdHRhY2htZW50cyI6W3siY29udGVudCI6eyJ0aXRsZSI6IkNvbm5lY3QgdG8gVGVzdEFwcDEiLCJ0ZXh0IjoiQ2xpY2sgU2lnbiBJbiBidXR0b24gdG8gY29ubmVjdCB5b3VyIFRlYW1zIGFjY291bnQgd2l0aCB5b3VyIFRlc3RBcHAxIGFjY291bnQiLCJpbWFnZXMiOlt7InVybCI6Imh0dHBzOi8vZXUtYXBpLmFzbS5za3lwZS5jb20vdjEvb2JqZWN0cy8wLXdldS1kOC01YTRhNjEzMjgyYzBhODRjY2JkYTFlNmVjNjcxYTY3Mi92aWV3cy9pbWdfcHJldmlldyJ9XSwiYnV0dG9ucyI6W3sidHlwZSI6Im9wZW5VcmwiLCJ0aXRsZSI6IlNpZ24gSW4iLCJ2YWx1ZSI6Imh0dHBzOi8vd3d3Lmdvb2dsZS5jb20ifV19LCJjb250ZW50VHlwZSI6ImFwcGxpY2F0aW9uL3ZuZC5taWNyb3NvZnQuY2FyZC5oZXJvIn1dLCJ0eXBlIjoibWVzc2FnZS9jYXJkIn0="><Description></Description></Swift></URIObject>
But If I change the chat/channel and go back, it is properly displayed.
It happens the same in a private chat with the bot and in a channel, writing to the bot (#bot)
Why can it be this "painting" problem?
My testing code:
this.onMessage(async (context, next) => {
...
//connectorClient, credentials, ...
...
var activity = context.activity;
var sConversationId = activity.conversation.id;
// Send text message 1
var message = MessageFactory.text("Text 1");
var response = await connectorClient.conversations.sendToConversation(sConversationId, message);
var sActivityId = response.id;
// Update message 1 with a Card
var jsonPath = __dirname + '/' + 'herocard_test.json';
const jsonCard = require(jsonPath);
var message2 = MessageFactory.attachment(CardFactory.adaptiveCard(jsonCard));
message2.id = sActivityId;
connectorClient.conversations.updateActivity(sConversationId, sActivityId, message2);
...
Thanks,
Diego

#Diego Thanks for reaching out!! We could repro this and we have raised a bug for it. We are working on fixing this.

Related

MS Teams - Don't show notification of specific message in the activity feed

Question
I have a simple Bot for MS Teams developed in C# with the Bot Builder SDK 3.15.0.0 targeting .NET framework 4.7.1.
When mentioned, it retrieves the Jira ticket Ids in the message and returns a single reply with a list of Cards, each one displaying a summary of a Jira Issue.
I'd like to know if it's possible to not populate the activity feed when sending the reply with the card attachments as it's not needed for my use case.
Example
This is how I usually build the reply to a user message
var reply = activity.CreateReply();
reply.AttachmentLayout = AttachmentLayoutTypes.List;
reply.Attachments = thumbnailCards;
await context.PostAsync(reply);
And this is what I tried after reading the docs at https://learn.microsoft.com/en-us/microsoftteams/platform/concepts/activity-feed#rest-api-sample
var reply = activity.CreateReply();
reply.AttachmentLayout = AttachmentLayoutTypes.List;
reply.Attachments = thumbnailCards;
reply.ChannelData = JsonConvert.SerializeObject(new
{
notification = new
{
alert = false
}
});
await context.PostAsync(reply);
I was hoping that setting the ChannelData with notification.alert = false would just disable the notifications, but it actually doesn't display any message.
Have you tried using the Teams nuget package: https://www.nuget.org/packages/Microsoft.Bot.Connector.Teams
var reply = activity.CreateReply();
reply.ChannelData = JObject.FromObject(new TeamsChannelData()
{
Notification = new NotificationInfo(false)
});
Source for this package can be found here: https://github.com/OfficeDev/BotBuilder-MicrosoftTeams/
The alert you are getting in the activity feed is simply the "someone replied to your message" alert and is nothing special coming from the bot. This notification in the activity feed cannot be disabled as of now. Other team members won't receive this alert in activity feed unless they are following the same channel.
Sending notification using Rest API is designed to work for 1:1 chat.

Having issue in conversation of UCMA with MS Bot Framework

I am working on MS Bot Framework Integration with UCMA(Skype For Business OnPremise aka SFB onPrimise) SDK.
I am using directline channel for connection and the Connection is successfully established between two, but when a dialog prompt with Yes, No options is returned From BOT to SFB, and when I send my answer as yes then BOT do not recognize it as my answer. It creates new conversation Id for every single statement. How to overcome this issue?
Below is my code from UCMA
static DirectLineClient client = null;
client = new Microsoft.Bot.Connector.DirectLine.DirectLineClient("DirectLineSecretKey");
botConversation = client.Conversations.NewConversation();
string message = e.TextBody;
Microsoft.Bot.Connector.DirectLine.Models.Message msg = new Microsoft.Bot.Connector.DirectLine.Models.Message
{
FromProperty = "AMOL",
Text = message
};
await client.Conversations.PostMessageAsync(botConversation.ConversationId, msg);
var messages = await client.Conversations.GetMessagesAsync(botConversation.ConversationId, watermark);
InstantMessagingFlow instantMessagingFlow = (InstantMessagingFlow)sender;
watermark = messages.Watermark;
foreach (var m in messages.Messages)
{
if (m.FromProperty != "AMOL")
instantMessagingFlow.BeginSendInstantMessage(m.Text, MyMethod, instantMessagingFlow);
}
I am doing the same and it works for me. The problem in your code is, you create conversation id for each and every request and bot is considering the request as new fresh new request.
Let me know if you need any help on this.

Proactive Bot Messaging - CreateDirectConversation - unauthorized exception

I am creating a bot to proactively start a conversation with an account I have never had a previous conversation with. I have created another controller that I am posting to and doing the following steps:
public class OutboundController : ApiController {
public HttpResponseMessage Post([FromUri] int id, [FromBody] OutboundData outboundData) {
MicrosoftAppCredentials.TrustServiceUrl(outboundData.ServiceUrl);
//create conversation
var connector = new ConnectorClient(new Uri(outboundData.ServiceUrl));
var botAccount = new ChannelAccount { Id = outboundData.FromAccountId, Name = outboundData.FromAccountName };
var toAccount = new ChannelAccount { Id = outboundData.ToAccountId, Name = outboundData.ToAccountName };
if(!MicrosoftAppCredentials.IsTrustedServiceUrl(outboundData.ServiceUrl)) {
throw new Exception("service URL is not trusted!");
}
var conversationResponse = connector.Conversations.CreateDirectConversation(botAccount, toAccount);
var client = new BuslogicClient();
var confirmData = client.GetOutboundData(id);
var greetingMessage = CreateGreetingMessage(confirmData);
var convoMessage = Activity.CreateMessageActivity();
convoMessage.Text = greetingMessage;
convoMessage.From = botAccount;
convoMessage.Recipient = toAccount;
convoMessage.Conversation = new ConversationAccount(id: conversationResponse.Id);
convoMessage.Locale = "en-Us";
connector.Conversations.SendToConversationAsync((Activity)convoMessage);
string message = string.Format("I received correlationid:{0} and started conversationId:{1}", id, conversationResponse.Id);
var response = Request.CreateResponse(HttpStatusCode.OK, message);
return response;
}
When I call connector.Conversations.CreateDirectConversation I am getting the following exception: Additional information: Authorization for Microsoft App ID [ID] failed with status code Unauthorized and reason phrase 'Unauthorized'. If I do this with appId and password blank everything works fine in the channel emulator. I've tried providing the MicrosoftAppCredentials to the constructor of the ConnectorClient, but that has no affect. I've read on other threads that the service URL must be trusted so I used MicrosoftAppCredentials.TrustServiceUrl.
versions I am using:
BotBuilder 3.5.3
Channel Emulator 3.0.0.59
The use-case for my bot is to post to the outbound controller with some user info to create a proactive message to be sent out (specifically SMS). If the user responds to my message it will be intercepted by the messages controller and passed to my dialogs for further processing and conversation responses on that same channel.
I've also taken a look at: https://github.com/Microsoft/BotBuilder/issues/2155 but don't quite understand solution described in the comments or if it even pertains to the issue I'm trying to solve.
Any suggestions or help would be appreciated!
You need to pass credentials explicitly to connector:
var credentials = new MicrosoftAppCredentials("YoursMicrosoftAppId", "YoursMicrosoftAppPassword");
var connector = new ConnectorClient(serviceUrl, credentials);

How do I email from BotFramework from Intent

I am looking for an example of how to send an email from a botframework intent.
I have tried the code below but nothing gets sent. I am doing something wrong?
[LuisIntent("TestEmailIntent")]
public async Task FindFundFactSheetAsync(IDialogContext context, LuisResult result)
{
var emailMessage = context.MakeMessage();
emailMessage.Recipient.Id = "myEmail#hotmail.com";
emailMessage.Recipient.Name = "John Cleophas";
emailMessage.Text ="Test message"
var data = new EmailContentData();
var channelData = Newtonsoft.Json.JsonConvert.SerializeObject(data);
emailMessage.ChannelData = channelData;
await context.PostAsync(emailMessage);
context.Wait(MessageReceived);
}
Unless your bot is employing the email channel, you will need to send the email message using your own code, not via the BotFramework. Any posts will go back to the original channel (i.e. Skype, Facebook, etc.)

Sending message from bot to a Skype User using Botframework Version 3

Updated
I am developing a Skype bot with 1:1 conversation with Bot Framework.
In that I have a WebHook method which will call from an external service and sends message to my bot, then my bot will send that message to a skype user.
The following code is for v1 in message controller along with api/messages post method
public async Task<Message> Post([FromBody]Message message){}
[Route("~/api/messages/hook")]
[HttpPost]
public async Task<IHttpActionResult> WebHook([FromBody]WebHookMessage message)
{
if (message.Type == "EmotionUpdate")
{
const string fromBotAddress = "<Skype Bot ID here>";
const string toBotAddress = "<Destination Skype name here>";
var text = resolveEmoji(message.Data);
using (var client = new ConnectorClient())
{
var outMessage = new Message
{
To = new ChannelAccount("skype", address: toBotAddress , isBot: false),
From = new ChannelAccount("skype", address: $"8:{fromBotAddress}", isBot: true),
Text = text,
Language = "en",
};
await client.Messages.SendMessageAsync(outMessage);
}
}
return Ok();
}
I will call above WebHook from another service, so that my bot will send messages to the respective skype user.
Can anyone please help me how can I achieve the same in V3 bot framework?
I tried the following but not working
const string fromBotAddress = "Microsoft App ID of my bot";
const string toBotAddress = "skype username";
WebHookMessage processedData = JsonConvert.DeserializeObject<WebHookMessage>(message);
var text = resolveEmoji(processedData.Data);
using (var client = new ConnectorClient(new Uri("https://botname.azurewebsites.net/")
, "Bot Microsoft App Id", "Bot Microsoft App secret",null))
{
var outMessage = new Activity
{
ReplyToId = toBotAddress,
From = new ChannelAccount("skype", $"8:{fromBotAddress}"),
Text = text
};
await client.Conversations.SendToConversationAsync(outMessage);
}
But it is not working, finally what I want to achieve is I want my bot send a message to a user any time how we will send message to a person in skype.
The following code works, but there are some things that are not that obvious that I figured out (tested on Skype channel)
When a user interacts with the bot the user is allocated an id that can only be used from a specific bot..for example: I have multiple bots each using a skype channel. When I send a message from my skype user to bot A the id is different than for bot B. In the previous version of the bot framework I could just send a message to my real skype user id, but not anymore. In a way it simplifies the whole process because you only need the recipient's id and the framework takes care of the rest, so you don't have to specify a sender or bot Id (I guessed all that is linked behind the scenes)
[Route("OutboundMessages/Skype")]
[HttpPost]
public async Task<HttpResponseMessage> SendSkypeMessage(SkypePayload payload)
{
using (var client = new ConnectorClient(new Uri("https://skype.botframework.com")))
{
var conversation = await client.Conversations.CreateDirectConversationAsync(new ChannelAccount(), new ChannelAccount(payload.ToSkypeId));
IMessageActivity message = Activity.CreateMessageActivity();
message.From = new ChannelAccount();
message.Recipient = new ChannelAccount(payload.ToSkypeId);
message.Conversation = new ConversationAccount { Id= conversation.Id };
message.Text = payload.MessageBody;
await client.Conversations.SendToConversationAsync((Activity)message);
}
return Request.CreateResponse(HttpStatusCode.OK);
}
I'm not sure I understand what you're trying to do. If you'd like to answer a message (activity), try something like this:
ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
var reply = activity.createReply(text, "en");
await connector.Conversations.ReplyToActivityAsync(reply);
Activity.createReply switches the From and Recipient fields from the incoming activity. You can also try setting these field manually.
UPDATE
You need to create a ConnectorClient to the Skype Connector Service, not to your bot! So try with the Uri http://skype.botframework.com it might work.
However, I don't think you can message a user on Skype without receiving a message from it in the first place (i.e. your bot needs to be added to the user's contacts). Once you have an incoming message from the user, you can use it the create replies, just as described above.
WebHookMessage processedData = JsonConvert.DeserializeObject<WebHookMessage>(message);
var text = resolveEmoji(processedData.Data);
var client = new ConnectorClient(new Uri(activity.serviceUrl));
var outMessage = activity.createReply(text);
await client.Conversations.SendToConversationAsync(outMessage);
activity is a message received from the given user earlier. In this case, activity.serviceUrl should be http://skype.botframework.com, but generally you should not rely on this.
You can try to create the activity (outMessage) manually; for that, I'd recommend inspecting the From and Recipient fields of a message coming from a Skype user and setting these fields accordingly. However, as mentioned before, your bot needs to be added to the user's contacts, so at this point it will have received a message from the user.

Resources