-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Added first-pass declaration file for Typescript. #494
Conversation
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! 👍 |
is there any reason why this is not included? |
…essage documentation
repeat(): never; | ||
silentRepeat(): never; | ||
addQuestion(message: Message, cb: Function, capture_options, thread): never; | ||
ask(message: Message, cb: Function, capture_options): never; |
There was a problem hiding this comment.
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:
cb
might be eitherFunction
orarray of mapping of keyword to callback
.message
might be eitherstring
orMessage
.
See: https://github.com/howdyai/botkit#using-conversationask-with-an-array-of-callbacks
Example: https://github.com/howdyai/botkit#using-conversationask-with-an-array-of-callbacks
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?
News about this? How can we help? |
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
@aaronsky can you update the PR with the changes mentioned by @indierojo ? Or shall I clone your repo and make another PR? |
This PR was superseded by #953, please close it. |
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.