Skip to content

Commit

Permalink
fix the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
KhudaDad414 committed Jan 10, 2024
1 parent 155ea81 commit c7a221e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
8 changes: 5 additions & 3 deletions docs/pages/function-lifecycle-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ Functions take a single argument, which is the event received from a broker or a
|channel|The name of the channel/topic from which the event was read.
|serverName|The name of the server/broker from which the event was received.

Functions may return an object to tell Glee what to do next. For instance, the following example greets the user back:
Functions may return an object to tell Glee what to do next. For instance, the following example sends a greeting message to `development` server:
```js
/* onHello.js */
export default async function (event) {
return {
reply: [{
send: [{
server: 'developement',
channel: 'greets',
payload: 'Greetings! How is your day going?'
}]
}
Expand All @@ -37,7 +39,7 @@ export default async function (event) {
|Attribute|Type|Description|
|---|---|---|
|send|array<[OutboundMessage](#anatomy-of-an-outbound-message)>|A list of outbound messages to send when the processing of the inbound event has finished. All clients subscribed to the given channel/topic will receive the message.
|reply|array<[OutboundMessage](#anatomy-of-an-outbound-message)>|A list of outbound messages to send as a reply when the processing of the inbound event has finished. This is useful when the target of your message is the sender of the inbound event. Note, however, that this only works when you're running Glee as a server. For example, using `reply` when receiving a WebSocket message is fine and the reply will exclusively go to the client that sent the message. However, if you're receiving a message from an MQTT broker, `reply` will work exactly the same way as `send` above, and will send the message to all the clients subscribed to the given channel/topic.

##### Anatomy of an outbound message
|Attribute|Type|Description|
|---|---|---|
Expand Down
10 changes: 2 additions & 8 deletions docs/pages/glee-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ operations:
action: receive
channel:
$ref: '#/channels/hello'
reply:
channel:
$ref: "#/channels/hello"
SendHello:
action: send
channel:
Expand Down Expand Up @@ -73,9 +70,6 @@ operations:
action: receive
channel:
$ref: '#/channels/hello'
reply:
channel:
$ref: "#/channels/hello"
sendHello:
action: send
channel:
Expand All @@ -84,8 +78,8 @@ operations:

The channels section defines the communication channels available in the API. In this case, there's a channel named "hello". This channel supports both sending and receiving.

The `receive` action indicates that messages received on the `hello` channel should follow the structure defined in the hello message component. Under this action, `reply` which is in a request-reply operation, contains the payload on `onHello.js` function.
The `send` action specifies that the operation with ID `sendHello` is used for sending messages to the `hello` channel. The message structure is referenced from the hello message component.
The `receive` action indicates that messages received on the `hello` channel should follow the structure defined in the hello message component.
The `send` action specifies that the operation with ID `sendHello` is used for sending messages to the `hello` channel. The message structure is referenced from the hello message component. The message payload is going to be validated against the `sendHello` operation message schemas.

Next is the `payload` property under `hello` message component which is used to understand how the event should look like when publishing to that channel:

Expand Down
7 changes: 3 additions & 4 deletions docs/pages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ operations:
action: receive
channel:
$ref: '#/channels/greet'
reply:
channel:
$ref: '#/channels/greet'
sendGreet:
action: send
channel:
Expand Down Expand Up @@ -127,8 +124,10 @@ export default async function (event) {
response = `Good Evening ${name}`
}
return {
reply: [
send: [
{
server: "websockets",
channel: "greet"
payload: response,
},
],
Expand Down
7 changes: 3 additions & 4 deletions docs/pages/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ operations:
action: receive
channel:
$ref: '#/channels/hello'
reply:
channel:
$ref: "#/channels/hello"
SendHello:
action: send
channel:
Expand All @@ -121,7 +118,9 @@ Create an operation function `onHello.js` inside `myapp/functions`:
```js
export default async function (event) {
return {
reply: [{
send: [{
server: "websockets",
channel: "hello",
payload: `Hello from Glee! You said: "${event.payload}".`
}]
}
Expand Down

0 comments on commit c7a221e

Please sign in to comment.