-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chatfly init * [Components] chatfly #11730 Actions - SendMessage * pnpm update * Update components/chatfly/chatfly.app.mjs * fix description --------- Co-authored-by: Leo Vu <[email protected]>
- Loading branch information
1 parent
85482fc
commit e0d423e
Showing
5 changed files
with
139 additions
and
8 deletions.
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,45 @@ | ||
import chatfly from "../../chatfly.app.mjs"; | ||
|
||
export default { | ||
key: "chatfly-send-message", | ||
name: "Send Message", | ||
description: "Dispatches a text message to a specified group or individual in Chatfly.", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
chatfly, | ||
botId: { | ||
propDefinition: [ | ||
chatfly, | ||
"botId", | ||
], | ||
}, | ||
sessionId: { | ||
propDefinition: [ | ||
chatfly, | ||
"sessionId", | ||
({ botId }) => ({ | ||
botId, | ||
}), | ||
], | ||
}, | ||
message: { | ||
propDefinition: [ | ||
chatfly, | ||
"message", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.chatfly.dispatchMessage({ | ||
$, | ||
data: { | ||
bot_id: this.botId, | ||
message: this.message, | ||
session_id: this.sessionId, | ||
}, | ||
}); | ||
$.export("$summary", "Message dispatched successfully"); | ||
return response; | ||
}, | ||
}; |
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 |
---|---|---|
@@ -1,11 +1,86 @@ | ||
import { axios } from "@pipedream/platform"; | ||
import { prepareSessionLabel } from "./common/utils.mjs"; | ||
|
||
export default { | ||
type: "app", | ||
app: "chatfly", | ||
propDefinitions: {}, | ||
propDefinitions: { | ||
botId: { | ||
type: "string", | ||
label: "Bot ID", | ||
description: "The ID of the bot to send the message to.", | ||
async options() { | ||
const data = await this.listBots(); | ||
|
||
return data.map(({ | ||
id: value, bot_name: label, | ||
}) => ({ | ||
label, | ||
value, | ||
})); | ||
}, | ||
}, | ||
message: { | ||
type: "string", | ||
label: "Message", | ||
description: "The message to send.", | ||
}, | ||
sessionId: { | ||
type: "string", | ||
label: "Session ID", | ||
description: "The session ID for the message. To initiate a new session, use a unique string in a Custom Expression, for example: `8g12h`", | ||
async options({ botId }) { | ||
const data = await this.listSessions({ | ||
params: { | ||
bot_id: botId, | ||
}, | ||
}); | ||
|
||
return data.map(({ | ||
session_id: value, chat_history_response, | ||
}) => ({ | ||
label: prepareSessionLabel(chat_history_response), | ||
value, | ||
})); | ||
}, | ||
}, | ||
}, | ||
methods: { | ||
// this.$auth contains connected account data | ||
authKeys() { | ||
console.log(Object.keys(this.$auth)); | ||
_baseUrl() { | ||
return "https://backend.chatfly.co/api"; | ||
}, | ||
_headers() { | ||
return { | ||
"CHATFLY-API-KEY": `${this.$auth.api_key}`, | ||
}; | ||
}, | ||
_makeRequest({ | ||
$ = this, path = "/", ...opts | ||
}) { | ||
return axios($, { | ||
url: this._baseUrl() + path, | ||
headers: this._headers(), | ||
...opts, | ||
}); | ||
}, | ||
dispatchMessage(opts = {}) { | ||
return this._makeRequest({ | ||
method: "POST", | ||
path: "/chat/get-streaming-response", | ||
...opts, | ||
}); | ||
}, | ||
listBots(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/bot", | ||
...opts, | ||
}); | ||
}, | ||
listSessions(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/chat/history", | ||
...opts, | ||
}); | ||
}, | ||
}, | ||
}; | ||
}; |
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,5 @@ | ||
export const prepareSessionLabel = (messages) => { | ||
return `${messages[messages.length - 1].content.substring(0, 60)} ${(messages[messages.length - 1].content.length > 60) | ||
? "..." | ||
: ""}`; | ||
}; |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@pipedream/chatfly", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Pipedream ChatFly Components", | ||
"main": "chatfly.app.mjs", | ||
"keywords": [ | ||
|
@@ -11,5 +11,8 @@ | |
"author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@pipedream/platform": "^1.6.5" | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.