-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
feat: add request/reply support #551
Merged
Merged
Changes from 5 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
044823a
initial commit
KhudaDad414 62b7076
initial commit
KhudaDad414 2b40e2f
Merge remote-tracking branch 'upstream/master' into v3-playground
KhudaDad414 1ada3d4
initial draft
KhudaDad414 839c82c
Merge branch 'v3-playground' into request-reply
KhudaDad414 8b97e96
use better names for channels and operations
KhudaDad414 224391c
add readme
KhudaDad414 a498823
update readme
KhudaDad414 ac4c281
re-enable send
KhudaDad414 8c3f8f9
Merge branch 'master' into request-reply
KhudaDad414 37c929e
Merge branch 'master' into request-reply
KhudaDad414 a7cca8b
refactor
KhudaDad414 b214597
add tests
KhudaDad414 8b3000c
remove warnings
KhudaDad414 202176f
Update src/adapters/http/client.ts
KhudaDad414 494d8a7
Update src/lib/adapter.ts
KhudaDad414 73e2030
Update src/lib/functions.ts
KhudaDad414 02555cb
Update src/lib/functions.ts
KhudaDad414 8e5a1a1
Update src/lib/functions.ts
KhudaDad414 e585f17
final touches
KhudaDad414 9e99f90
modify reply generation
KhudaDad414 c383d35
fix reply checking logic
KhudaDad414 ef0ba2d
Update src/lib/functions.ts
KhudaDad414 5c7bd6b
Update src/lib/functions.ts
KhudaDad414 8854982
Merge remote-tracking branch 'upstream/master' into request-reply
KhudaDad414 ab29311
add receive operation
KhudaDad414 ddb5af3
Empty commit
KhudaDad414 1155325
fix for sonar
KhudaDad414 10cc240
fix eslint warnings
KhudaDad414 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
.glee |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Dummy | ||
|
||
This is a dummy example mainly used to test functionalities. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
asyncapi: 3.0.0 | ||
info: | ||
title: Slack Websocket API | ||
version: 1.0.0 | ||
servers: | ||
OpenAI: | ||
host: api.openai.com | ||
protocol: https | ||
Slack: | ||
host: wss-primary.slack.com | ||
protocol: wss | ||
Slack_HTTP: | ||
host: slack.com | ||
protocol: https | ||
channels: | ||
slackResponse: | ||
bindings: | ||
http: | ||
method: post | ||
address: /api/chat.postMessage | ||
servers: | ||
- $ref: "#/servers/Slack_HTTP" | ||
messages: | ||
slackResponse: | ||
$ref: "#/components/messages/slackResponse" | ||
OpenAISent: | ||
bindings: | ||
http: | ||
method: post | ||
servers: | ||
- $ref: "#/servers/OpenAI" | ||
address: /v1/chat/completions | ||
messages: | ||
OpenAIRequest: | ||
$ref: "#/components/messages/OpenAIRequest" | ||
slackReceive: | ||
servers: | ||
- $ref: "#/servers/Slack" | ||
address: /link/?ticket={ticket}&app_id={app_id} | ||
parameters: | ||
ticket: | ||
default: 35338c0f-ffcc-4325-b8d4-7c9e556c0ecf | ||
app_id: | ||
default: b02112d9364cb2fee8a0ee048a920b8b4b0103cb03fab023b4e30f6ee2efb98f | ||
messages: | ||
reactionAdded: | ||
$ref: "#/components/messages/reactionAdded" | ||
error: | ||
$ref: "#/components/messages/error" | ||
operations: | ||
slackResponse: | ||
|
||
action: send | ||
channel: | ||
$ref: "#/channels/OpenAISent" | ||
messages: | ||
- $ref: "#/components/messages/slackResponse" | ||
openAIResponse: | ||
action: receive | ||
channel: | ||
$ref: "#/channels/OpenAISent" | ||
messages: | ||
- $ref: "#/components/messages/OpenAIResponse" | ||
reply: | ||
channel: | ||
$ref: "#/channels/slackResponse" | ||
reactionAdded: | ||
reply: | ||
channel: | ||
$ref: "#/channels/OpenAISent" | ||
action: receive | ||
channel: | ||
$ref: "#/channels/slackReceive" | ||
messages: | ||
- $ref: "#/components/messages/reactionAdded" | ||
- $ref: "#/components/messages/error" | ||
|
||
components: | ||
messages: | ||
slackResponse: | ||
payload: | ||
type: object | ||
properties: | ||
channel: | ||
type: string | ||
text: | ||
type: string | ||
OpenAIRequest: | ||
payload: | ||
type: object | ||
properties: | ||
model: | ||
type: string | ||
enum: ["gpt-3.5-turbo", "gpt-3.5-turbo-16k", "text-davinci-002"] | ||
messages: | ||
type: array | ||
items: | ||
type: object | ||
properties: | ||
role: | ||
type: string | ||
enum: ["user"] | ||
content: | ||
type: string | ||
temperature: | ||
type: number | ||
minimum: 0.0 | ||
maximum: 1.0 | ||
required: | ||
- model | ||
- messages | ||
- temperature | ||
OpenAIResponse: | ||
payload: | ||
type: object | ||
properties: | ||
choices: | ||
type: array | ||
items: | ||
type: object | ||
properties: | ||
finish_reason: | ||
type: string | ||
enum: ['stop'] | ||
message: | ||
type: object | ||
properties: | ||
content: | ||
type: string | ||
role: | ||
type: string | ||
enum: ['assistant'] | ||
required: | ||
- finish_reason | ||
- message | ||
required: | ||
- choices | ||
reactionAdded: | ||
payload: | ||
type: object | ||
error: | ||
payload: | ||
type: string | ||
x-remoteServers: | ||
- Slack_HTTP | ||
- Slack | ||
- OpenAI |
25 changes: 25 additions & 0 deletions
25
examples/slack-reaction-listener/functions/openAIResponse.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { GleeFunction } from "@asyncapi/glee" | ||
|
||
const myFunction: GleeFunction = async (event) => { | ||
const { payload } = event.request.request; | ||
const slack_event = payload?.payload?.event | ||
|
||
if (!slack_event) return | ||
|
||
const thread_ts = slack_event.item.ts | ||
const channel = slack_event.item.channel | ||
const text = event.payload.choices[0].message.content | ||
|
||
|
||
return { | ||
payload: { | ||
channel, thread_ts, text | ||
}, | ||
headers: { | ||
Authorization: `Bearer ${process.env.SLACK_HTTP}`, | ||
} | ||
} | ||
|
||
} | ||
|
||
export default myFunction |
24 changes: 24 additions & 0 deletions
24
examples/slack-reaction-listener/functions/reactionAdded.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { GleeFunction } from "@asyncapi/glee" | ||
enum EVENT_TYPE { | ||
EVENTS_API = "events_api", | ||
CONNECTED = "hello" | ||
} | ||
const myFunction: GleeFunction = async ({ payload }) => { | ||
const reaction = payload?.payload?.event?.reaction | ||
if (!reaction) return | ||
KhudaDad414 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return { | ||
headers: { | ||
'Authorization': `Bearer ${process.env.CHAT_API}` | ||
}, | ||
|
||
payload: { | ||
model: "gpt-3.5-turbo", | ||
messages: [{ "role": "user", "content": `Someone reacted with "${reaction}" to my message on Slack, write something fun and short to them.` }], | ||
temperature: 0.7 | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
export default myFunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default async function () { | ||
return { | ||
docs: { | ||
enabled: false | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
just remember that these should go through websocket binding query field - but of course if that is not supported, parameters are good temporary solution, although in future address should be validated by parser, if not yet
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.
Will update it to use the bindings.
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.
#591