infracloudio / msbotbuilder-go

Microsoft Bot Framework SDK for Go
MIT License
139 stars 39 forks source link

Added support for activity update #51

Closed sbawaskar closed 3 years ago

sbawaskar commented 4 years ago

Addresses #35.

sbawaskar commented 4 years ago

@PrasadG193 , please review.

PrasadG193 commented 4 years ago

Thanks for the PR @sbawaskar. Will it be possible to add a sample for this under https://github.com/infracloudio/msbotbuilder-go/tree/develop/samples? You can add the same example you are using for testing

sbawaskar commented 4 years ago

Thanks for the PR @sbawaskar. Will it be possible to add a sample for this under https://github.com/infracloudio/msbotbuilder-go/tree/develop/samples? You can add the same example you are using for testing

Will add a sample and test for that sample.

sbawaskar commented 4 years ago

@PrasadG193 , to update an activity we need ID of activity which was previously created by bot. Example, on an approval card, approval button is removed once user click on approve button. With current implementation of SDK I did not find a way to get activity ID which bot created. Any insight on this?

PrasadG193 commented 4 years ago

@sbawaskar We will have to store the activity ID which we want to update. E.g in proactive activity sample (https://github.com/infracloudio/msbotbuilder-go/blob/develop/samples/proactive/main.go#L89), we save conv ref when the user sends a message. Later we proactively send a welcome message to the same conversation using ref we store

sbawaskar commented 4 years ago

@sbawaskar We will have to store the activity ID which we want to update. E.g in proactive activity sample (https://github.com/infracloudio/msbotbuilder-go/blob/develop/samples/proactive/main.go#L89), we save conv ref when the user sends a message. Later we proactively send a welcome message to the same conversation using ref we store

Conversation reference is saved and that works for proactive message. For activity update we need activity ID. Getting below error when I try to apply conversation reference and use that activity in update call.

https://smba.trafficmanager.net/in/v3/conversations/a:1lFpRAr-rUSU7muWrjctS2Cl1t0fHQLinwHybvsmNfzczNldZvwiDfDuQuCGpC7yftxsm8L-YCMTmz2xVyuxB2TZqpwI4HD7cHuPjoB6KfuqNix0AM2ZKznr0JekpD69Y/activities/1603215439486
{"error":{"code":"ServiceError","message":"Unknown"}}

Sample code,

activityInstance, err := ht.Adapter.ParseRequest(ctx, req)
    if err != nil {
        fmt.Println("Failed to parse request.", err)
        http.Error(w, err.Error(), http.StatusBadRequest)
        return
    }

    err = ht.Adapter.ProcessActivity(ctx, activityInstance, customHandler)
    if err != nil {
        fmt.Println("Failed to process request", err)
        http.Error(w, err.Error(), http.StatusBadRequest)
        fmt.Println(err.Error())
        return
    }
    conversationRef := activity.GetCoversationReference(activityInstance)
    act := activity.ApplyConversationReference(schema.Activity{Type: schema.Message}, conversationRef, true)
    if activityID != "" {
        act.Text = "Changed Activity"
        act.ID = activityID
        err = ht.Adapter.UpdateActivity(ctx, act)
        if err != nil {
            fmt.Println("Failed to process request", err)
            http.Error(w, err.Error(), http.StatusBadRequest)
            fmt.Println(err.Error())
            return
        }
                // activityID is a global variable. We save previous posted activity ID and keep on updating it.
        activityID = conversationRef.ActivityID
    } else {
        activityID = conversationRef.ActivityID
    }
    fmt.Println("Request processed successfully.")

Note : Python API for bot builder returns activity ID as response when an activity is created. Our API just returns an error.

sbawaskar commented 3 years ago

@PrasadG193 , Added sample for activity update. Please check. Using RepyToID from adaptive card event to update activity.

sbawaskar commented 3 years ago

@PrasadG193 , reminder for review.

sbawaskar commented 3 years ago

@PrasadG193 , reminder for review.

PrasadG193 commented 3 years ago

Thank you @sbawaskar. Please give me some time, I will try to review it tomorrow.

sbawaskar commented 3 years ago

@PrasadG193 , addressed code review comments, please review.