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

feat: add request/reply support #551

Merged
merged 29 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
044823a
initial commit
KhudaDad414 Oct 20, 2023
62b7076
initial commit
KhudaDad414 Oct 25, 2023
2b40e2f
Merge remote-tracking branch 'upstream/master' into v3-playground
KhudaDad414 Oct 26, 2023
1ada3d4
initial draft
KhudaDad414 Oct 30, 2023
839c82c
Merge branch 'v3-playground' into request-reply
KhudaDad414 Oct 30, 2023
8b97e96
use better names for channels and operations
KhudaDad414 Nov 1, 2023
224391c
add readme
KhudaDad414 Nov 3, 2023
a498823
update readme
KhudaDad414 Nov 3, 2023
ac4c281
re-enable send
KhudaDad414 Nov 6, 2023
8c3f8f9
Merge branch 'master' into request-reply
KhudaDad414 Nov 8, 2023
37c929e
Merge branch 'master' into request-reply
KhudaDad414 Nov 8, 2023
a7cca8b
refactor
KhudaDad414 Nov 9, 2023
b214597
add tests
KhudaDad414 Nov 9, 2023
8b3000c
remove warnings
KhudaDad414 Nov 10, 2023
202176f
Update src/adapters/http/client.ts
KhudaDad414 Nov 15, 2023
494d8a7
Update src/lib/adapter.ts
KhudaDad414 Nov 15, 2023
73e2030
Update src/lib/functions.ts
KhudaDad414 Nov 15, 2023
02555cb
Update src/lib/functions.ts
KhudaDad414 Nov 15, 2023
8e5a1a1
Update src/lib/functions.ts
KhudaDad414 Nov 15, 2023
e585f17
final touches
KhudaDad414 Nov 15, 2023
9e99f90
modify reply generation
KhudaDad414 Nov 15, 2023
c383d35
fix reply checking logic
KhudaDad414 Nov 17, 2023
ef0ba2d
Update src/lib/functions.ts
KhudaDad414 Nov 20, 2023
5c7bd6b
Update src/lib/functions.ts
KhudaDad414 Nov 20, 2023
8854982
Merge remote-tracking branch 'upstream/master' into request-reply
KhudaDad414 Nov 20, 2023
ab29311
add receive operation
KhudaDad414 Nov 20, 2023
ddb5af3
Empty commit
KhudaDad414 Nov 20, 2023
1155325
fix for sonar
KhudaDad414 Nov 20, 2023
10cc240
fix eslint warnings
KhudaDad414 Nov 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/slack-reaction-listener/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.glee
3 changes: 3 additions & 0 deletions examples/slack-reaction-listener/README.md
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.
147 changes: 147 additions & 0 deletions examples/slack-reaction-listener/asyncapi.yaml
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}
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

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 examples/slack-reaction-listener/functions/openAIResponse.ts
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 examples/slack-reaction-listener/functions/reactionAdded.ts
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
7 changes: 7 additions & 0 deletions examples/slack-reaction-listener/glee.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default async function () {
return {
docs: {
enabled: false
}
}
}
Loading