Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Added first-pass declaration file for Typescript. #494

Closed
wants to merge 2 commits into from
Closed

Added first-pass declaration file for Typescript. #494

wants to merge 2 commits into from

Conversation

aaronsky
Copy link

This PR partially addresses #192. I have scanned the Slack and core pieces of botkit for necessary declaration matter and I wanted to get a discussion going around including this. Bundling the declaration file makes use with TypeScript much easier than going through DefinitelyTyped, so hopefully I can get some feedback on this from people and maybe make some progress on the not-Slack parts of the codebase.

@MattJeanes
Copy link

This looks great, one of the only things that was putting me off from using BotKit was the lack of TypeScript declarations - I still use it but I ended up writing something similar but a lot more lightweight than this. I really hope this gets officially included soon! 👍

@peterswimm peterswimm changed the title Added first-pass declaration file Added first-pass declaration file for Typescript. Nov 17, 2016
@theluk
Copy link

theluk commented Nov 25, 2016

is there any reason why this is not included?

repeat(): never;
silentRepeat(): never;
addQuestion(message: Message, cb: Function, capture_options, thread): never;
ask(message: Message, cb: Function, capture_options): never;
Copy link
Contributor

Choose a reason for hiding this comment

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

Using this type definition, found some odd types in Conversation class:

It works for my project:

diff --git a/botkit.d.ts b/botkit.d.ts
index eac474b..ffd615a 100644
--- a/botkit.d.ts
+++ b/botkit.d.ts
@@ -373,8 +373,8 @@ declare module botkit {
         next(): never;
         repeat(): never;
         silentRepeat(): never;
-        addQuestion(message: Message, cb: Function, capture_options, thread): never;
-        ask(message: Message, cb: Function, capture_options): never;
+        addQuestion(message: string | Message, cb: Function | {pattern?: string | RegExp, callback: Function, default?: boolean}[], capture_options, thread): never;
+        ask(message: string | Message, cb: Function | {pattern?: string | RegExp, callback: Function, default?: boolean}[], capture_options): never;
         addMessage(message: Message, thread): never;
         /**
          * how long should the bot wait while a user answers?

@cesarvarela
Copy link

cesarvarela commented Feb 5, 2017

News about this? How can we help?

@r-arias
Copy link

r-arias commented Apr 21, 2017

I'm definitely very interested in this being included.

startPrivateConversation(message: Message, cb: (err: Error, convo: Conversation) => void): never;
startConversation(message: Message, cb: (err: Error, convo: Conversation) => void): never;
createConversation(message: Message, cb: (err: Error, convo: Conversation) => void): never;
private _startDM(task: Task, user_id: string, cb: Function): any;

Choose a reason for hiding this comment

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

Any reason this was prefixed with private ?
Although the _ prefix does seem to imply that, at implementation there's no evidence that it should be enforced or that we should break usages of the method in the wild.

reply(src: Message, resp: string, cb?: (err?: string | Error) => void): never;
say(message: Message, cb?: (err?: string | Error) => void): never;
startTyping(src: any): never;
replyWithTyping(src: any, resp: string, cb: (err?: string | Error) => void): never;

Choose a reason for hiding this comment

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

cb is optional here -- and probably most places

private _startDM(task: Task, user_id: string, cb: Function): any;
send(message: Message, cb: (err?: string | Error) => void): never;
replyAcknowledge(cb: (err?: string | Error) => void): never;
replyPublic(src: any, resp: string, cb: (err?: string | Error) => void): never;

Choose a reason for hiding this comment

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

All of the reply methods also support a different reply type:

    interface Reply {
        username: string,
        attachments: Array<Attachment>
    }

resp: string should be resp: string | Reply for each of the following:

  • replyPublic
  • replyPublicDelayed
  • replyPrivate
  • replyPrivateDelayed
  • replyInteractive
  • reply
  • replyWithTyping
  • replyAndUpdate

@pascalwhoop
Copy link

@aaronsky can you update the PR with the changes mentioned by @indierojo ? Or shall I clone your repo and make another PR?

@uny uny mentioned this pull request Aug 11, 2017
@Naktibalda
Copy link
Contributor

This PR was superseded by #953, please close it.

@benbrown benbrown closed this Aug 30, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.