1

I am trying to update message sent by the bot to the user. The use case is to keep updating the card with status changes on a background process. I am using v4 of bot framework and nodejs for implementing the bot.

I am trying to use adapter.continueConversation() communicate status changes as shown in code snippet.

server.post('/api/notify', (req, res) => {
    const conversationReference: ConversationReference = conversationReferences[req.query.refId]; //stored conversation references   
    adapter.continueConversation(conversationReference, async (context) => {
        //stored activities
        const activity: Partial<Activity> = activityMap[req.query.i];
        let updatedActivity: Partial<Activity> = {};
        updatedActivity.id = req.query.id || activity.id;
        updatedActivity.text = 'Finally updated';
        updatedActivity.serviceUrl = activity.serviceUrl;
        updatedActivity.conversation = activity.conversation;
        console.log(updatedActivity);
        await context.updateActivity(updatedActivity); //Error
    });
    res.send(200);
    res.end();
});

JSON for activity to be updated

{
  "attachmentLayout": "list",
  "attachments": [
    {
      "content": {
        "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
        "body": [
          {
            "size": "Small",
            "text": "Dummy Text",
            "type": "TextBlock"
          }
        ],
        "type": "AdaptiveCard",
        "version": "1.0"
      },
      "contentType": "application/vnd.microsoft.card.adaptive"
    }
  ],
  "channelId": "emulator",
  "conversation": {
    "id": "87eaf011-9f4d-11e9-9f39-5522e8750ae9|livechat"
  },
  "from": {
    "id": "15fbd7c0-9ee0-11e9-9f39-5522e8750ae9",
    "name": "Bot",
    "role": "bot"
  },
  "id": "8de84b20-9f4d-11e9-be24-034531d2d092",
  "inputHint": "acceptingInput",
  "localTimestamp": "2019-07-05T23:21:45+05:30",
  "locale": "en-US",
  "recipient": {
    "id": "fb9fddeb-e180-472b-91b7-b963ee7cf89b",
    "role": "user"
  },
  "replyToId": "8ddba0f0-9f4d-11e9-be24-034531d2d092",
  "serviceUrl": "http://localhost:62975",
  "timestamp": "2019-07-05T17:51:45.362Z",
  "type": "message"
}

I would think that the activity would be updated with the text 'Finally updated' but instead I get 'Error: not a known activity id'. The id is '8de84b20-9f4d-11e9-be24-034531d2d092' which matches the activity id already sent.

  • What channel(s) are you trying to implement this on (i.e. Web Chat, Facebook, MS Teams, etc.)? – Steven Kanberg Jul 16 '19 at 08:54
  • The final aim is to implement this for MS Teams, however the error above occurs when using emulator to test this code. I found a thread [link](https://github.com/Microsoft/BotFramework-Emulator/issues/1123) which says update and delete activity support does not exist for emulator, but the message is misleading if that's the case. – Asif Pathan Jul 16 '19 at 11:13

2 Answers2

0

Try using replyToId property to get the last context activity id example:

updatedActivity.id = context.activity.replyToId;
updatedActivity.serviceUrl = context.activity.serviceUrl;
await context.updateActivity(updatedActivity);
0

You might need to create the turnConext for sending the message.

const { TurnContext } = require('botbuilder');

const turnContext = await new TurnContext(adapter, conversationReference);
    await adapter.continueConversation(conversationReference, async () => {
        response = await turnContext.sendActivity({{Message or Card here}});
    });
p_sha
  • 1
  • 3