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

fix: Use correct types in signatures of before,after and postMessage #185

Merged
merged 1 commit into from
Jun 14, 2019

Conversation

Naktibalda
Copy link
Contributor

@Naktibalda Naktibalda commented Jun 12, 2019

I tried to add headers to payload using this code:

watsonMiddleware.before = async (message: BotkitMessage, payload: Payload) => {
        payload.headers = {
            'X-Watson-Learning-Opt-Out': 'true'
        };
        return payload;
    }

but compilation failed with:

src/bot.ts:104:17 - error TS2339: Property 'headers' does not exist on type 'Payload'.

104         payload.headers = {

Result of before hook is passed to postMessage which calls conversation.message(payload);
https://github.com/watson-developer-cloud/botkit-middleware/blob/v2.1.1/src/index.ts#L162-L163
https://github.com/watson-developer-cloud/botkit-middleware/blob/v2.1.1/src/utils.ts#L79-L84

message method is defined at https://github.com/watson-developer-cloud/node-sdk/blob/v4.2.0/assistant/v1.ts#L98

and it takes MessageParams type as the first argument:

public message(params: AssistantV1.MessageParams, callback?: AssistantV1.Callback<AssistantV1.MessageResponse>): Promise<any> | void {

@codecov-io
Copy link

codecov-io commented Jun 13, 2019

Codecov Report

Merging #185 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #185   +/-   ##
=======================================
  Coverage   77.27%   77.27%           
=======================================
  Files           2        2           
  Lines         110      110           
  Branches       23       23           
=======================================
  Hits           85       85           
  Misses         21       21           
  Partials        4        4

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f4b86da...a13cd05. Read the comment docs.

@Naktibalda
Copy link
Contributor Author

I realized that workspace_id is already defined in MessageParams, so there is no need to have Payload interface, but I kept it for backwards compatibility just in case someone is using it in their code.

I added MessageParams and MessageResponse to all places where they are appropriate - after, before and postMessage. Also MessageResponse is a type of watsonData field in BotkitWatsonMessage.

@Naktibalda Naktibalda changed the title Change Payload parent to MessageParams Use correct types in signatures of before,after and postMessage Jun 13, 2019
Copy link
Contributor

@germanattanasio germanattanasio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

I will merge it tomorrow because semantic-release is having problems with one of the dependencies so the release may fail today

@germanattanasio germanattanasio changed the title Use correct types in signatures of before,after and postMessage fix: Use correct types in signatures of before,after and postMessage Jun 14, 2019
@germanattanasio germanattanasio merged commit b29dc3d into master Jun 14, 2019
@watson-github-bot
Copy link
Member

🎉 This PR is included in version 2.1.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Naktibalda Naktibalda deleted the fix-payload-type branch June 17, 2019 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

4 participants