Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activity Id displayed in emulator doesn't match activity id from code #1604

Closed
BeigeBadger opened this issue May 30, 2019 · 2 comments · Fixed by #1665
Closed

Activity Id displayed in emulator doesn't match activity id from code #1604

BeigeBadger opened this issue May 30, 2019 · 2 comments · Fixed by #1665
Labels
Bug Your classic code defect

Comments

@BeigeBadger
Copy link

Version

4.4.2

Describe the bug

I am creating an activity the posting it into my bot. Unfortunately it looks like the ID that I provide the activity does not match the ID displayed in the JSON inspector.

The JSON is:

{
  "attachments": [
    {
      "content": {
        "buttons": [
          {
            "text": "PositiveFeedback|question:what is a skill|answer:A broad set of common capabilities exist which today, which require each developer to build themselves. Our Virtual Assistant solution includes a new Skill capability enabling new capabilities to be plugged into an Virtual Assistant through configuration only and provide an authentication mechanism for Skills to request tokens for down-stream activities.\nFind out more [here](https://github.com/Microsoft/AI/blob/master/solutions/Virtual-Assistant/docs/virtualassistant-skills.md).|activityid:f371dc50-8318-11e9-a9a4-4fbd3b8d2732|channelid:emulator",
            "title": "Yes",
            "type": "imBack",
            "value": "PositiveFeedback|question:what is a skill|answer:A broad set of common capabilities exist which today, which require each developer to build themselves. Our Virtual Assistant solution includes a new Skill capability enabling new capabilities to be plugged into an Virtual Assistant through configuration only and provide an authentication mechanism for Skills to request tokens for down-stream activities.\nFind out more [here](https://github.com/Microsoft/AI/blob/master/solutions/Virtual-Assistant/docs/virtualassistant-skills.md).|activityid:f371dc50-8318-11e9-a9a4-4fbd3b8d2732|channelid:emulator"
          },
          {
            "text": "NegativeFeedback|question:what is a skill|answer:A broad set of common capabilities exist which today, which require each developer to build themselves. Our Virtual Assistant solution includes a new Skill capability enabling new capabilities to be plugged into an Virtual Assistant through configuration only and provide an authentication mechanism for Skills to request tokens for down-stream activities.\nFind out more [here](https://github.com/Microsoft/AI/blob/master/solutions/Virtual-Assistant/docs/virtualassistant-skills.md).|activityid:f371dc50-8318-11e9-a9a4-4fbd3b8d2732|channelid:emulator",
            "title": "No",
            "type": "imBack",
            "value": "NegativeFeedback|question:what is a skill|answer:A broad set of common capabilities exist which today, which require each developer to build themselves. Our Virtual Assistant solution includes a new Skill capability enabling new capabilities to be plugged into an Virtual Assistant through configuration only and provide an authentication mechanism for Skills to request tokens for down-stream activities.\nFind out more [here](https://github.com/Microsoft/AI/blob/master/solutions/Virtual-Assistant/docs/virtualassistant-skills.md).|activityid:f371dc50-8318-11e9-a9a4-4fbd3b8d2732|channelid:emulator"
          }
        ],
        "subtitle": "",
        "title": "Click on the icons below to rate this answer"
      },
      "contentType": "application/vnd.microsoft.card.hero"
    }
  ],
  "channelId": "emulator",
  "conversation": {
    "id": "74aa38f1-8317-11e9-996c-452966995099|livechat"
  },
  "entities": [],
  "from": {
    "id": "67a0a4f0-8295-11e9-996c-452966995099",
    "name": "Bot",
    "role": "bot"
  },
  "id": "ef945e90-8319-11e9-a9a4-4fbd3b8d2732",
  "localTimestamp": "2019-05-31T08:31:42+12:00",
  "locale": "en-US",
  "recipient": {
    "id": "9c25fbce-849f-41e7-adf8-218bc84d1925",
    "role": "user"
  },
  "replyToId": "f371dc50-8318-11e9-a9a4-4fbd3b8d2732",
  "serviceUrl": "http://localhost:62661",
  "timestamp": "2019-05-30T20:31:42.841Z",
  "type": "message"
}

This activity is being created by the following code:

public static Activity GetHeroCardWithButtons(string cardTitle, List<HeroCardButton> buttons)
		{
			var chatActivity = Activity.CreateMessageActivity();
			var cardButtons = new List<CardAction>();

			foreach (HeroCardButton button in buttons)
			{
				cardButtons.Add(
					new CardAction()
					{
						Text = button.Value,
						Type = ActionTypes.ImBack,
						Title = button.Label,
						Value = button.Value
						//Value = " " // Thank you for your feedback here?
					});
				;
			}

			var plCard = new HeroCard()
			{
				Title = cardTitle,
				Subtitle = string.Empty,
				Buttons = cardButtons
			};

			var attachment = plCard.ToAttachment();

			chatActivity.Id = Guid.NewGuid().ToString();
			chatActivity.Attachments.Add(attachment);

			return (Activity)chatActivity;
		}

Evidence of the ID being created in code for the activity:

https://i.imgur.com/OPXMLZz.png

Checking the activity in the emulator:

https://i.imgur.com/q4ArHFb.png

Am I doing something wrong here when trying to find the activity ID?

Thanks.

Additional context

I am trying to use the activity id to Call the DeleteActivityAsync function but since the IDs don't match it fails.

@BeigeBadger BeigeBadger added the Bug Your classic code defect label May 30, 2019
@tonyanziano
Copy link
Contributor

tonyanziano commented Jun 26, 2019

I've found the code responsible for this issue, and it appears that the Emulator is in fact overwriting the id field on the incoming activity.

I don't think this is necessary because if you look at that same code path, we call postActivityToUser which then calls postage on the activity, which tries to use the existing id on the activity, otherwise it generates a new one. In the case of this code path, we are wiping the incoming id field every time, so a new GUID is always generated.

@justinwilaby or @compulim do either of you happen to have more context on this, or any idea on if this is necessary? If not, it should be an easy fix of just reusing the incoming activity's id or defaulting to null if the id field is missing.

===

Changing line 53 in replyToActivity.ts to activity.id = activity.id || null; results in the desired behavior:

image

@tonyanziano
Copy link
Contributor

I discussed this change with @compulim offline, and we have decided that there shouldn't be any adverse side effects to this change as long as you -- the user -- ensure that the activity ids are unique.

At that point the burden is on the user when modifying the activity id directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Your classic code defect
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants