-
Notifications
You must be signed in to change notification settings - Fork 0
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
Expiration check #46
Expiration check #46
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import fetch from "isomorphic-fetch"; | ||
import ReconnectingWebSocket from "reconnecting-websocket"; | ||
import { equals, adjust, omit } from "ramda"; | ||
import { equals, adjust, omit, findLast } from "ramda"; | ||
import { v4 as uuid } from "uuid"; | ||
|
||
// Bot response | ||
|
@@ -208,6 +208,20 @@ export const shouldReinitialize = ( | |
); | ||
}; | ||
|
||
const getLastExpirationTimestamp = ( | ||
responses: Response[], | ||
): number | undefined => { | ||
const lastExpirationResponse = findLast( | ||
(response) => | ||
response.type === "bot" && | ||
typeof response.payload.expirationTimestamp === "number", | ||
responses, | ||
); | ||
return lastExpirationResponse?.type === "bot" | ||
? lastExpirationResponse.payload.expirationTimestamp | ||
: undefined; | ||
}; | ||
|
||
export const createConversation = (config: Config): ConversationHandler => { | ||
let socket: ReconnectingWebSocket | undefined; | ||
|
||
|
@@ -303,6 +317,15 @@ export const createConversation = (config: Config): ConversationHandler => { | |
null; | ||
|
||
const sendToBot = async (body: BotRequest): Promise<void> => { | ||
const lastExpirationTimestamp = getLastExpirationTimestamp(state.responses); | ||
if ( | ||
typeof lastExpirationTimestamp === "number" && | ||
new Date().getTime() > lastExpirationTimestamp | ||
) { | ||
setState({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💭 this seems like it should raise an exception or signal in some way that there's a new conversation starting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @michaelglass totally with you there, we are discussing the behind-the-scenes way to do this, basically any 'your conversation has expired' type of text content needs to be controlled inside the platform, so you can imagine some kind of explicit special message passing will happen here, but later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sam-trost that sounds like a bit of a change in direction, I would rather have a discussion about it at some point this week. |
||
conversationId: uuid(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. curious how this works for a multimodal when someone is already on the phone. Should this fail hard instead of resetting with a new conversation ID? What's the UX here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This package does not cover multimodal. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh yeah! whoops |
||
}); | ||
} | ||
const bodyWithContext = { | ||
userId: state.userId, | ||
conversationId: state.conversationId, | ||
|
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.
minor nit (and less precise but)
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.
I would rather do more precise and a bit clearer on the data structure.