-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
618 additions
and
2 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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
{ | ||
"recommendations": ["ms-playwright.playwright"] | ||
"recommendations": [ | ||
"ms-playwright.playwright", | ||
"esbenp.prettier-vscode", | ||
"firsttris.vscode-jest-runner" | ||
] | ||
} |
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 |
---|---|---|
|
@@ -11,5 +11,6 @@ | |
"search.exclude": { | ||
"**/node_modules": true, | ||
"**/build": true | ||
} | ||
}, | ||
"eslint.validate": ["json"] | ||
} |
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 +1,2 @@ | ||
export * from './core/src/index' | ||
export * from './telegram/src/index' |
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,32 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.json"], | ||
"parser": "jsonc-eslint-parser", | ||
"rules": { | ||
"@nx/dependency-checks": "error" | ||
} | ||
}, | ||
{ | ||
"files": ["./package.json"], | ||
"parser": "jsonc-eslint-parser", | ||
"rules": { | ||
"@nx/nx-plugin-checks": "error" | ||
} | ||
} | ||
] | ||
} |
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,11 @@ | ||
# telegram | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
## Building | ||
|
||
Run `nx build telegram` to build the library. | ||
|
||
## Running unit tests | ||
|
||
Run `nx test telegram` to execute the unit tests via [Jest](https://jestjs.io). |
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,10 @@ | ||
/* eslint-disable */ | ||
export default { | ||
displayName: 'telegram', | ||
preset: '../../jest.preset.js', | ||
transform: { | ||
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }], | ||
}, | ||
moduleFileExtensions: ['ts', 'js', 'html'], | ||
coverageDirectory: '../../coverage/plugins/telegram', | ||
} |
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,10 @@ | ||
{ | ||
"name": "telegram", | ||
"version": "0.0.1", | ||
"dependencies": { | ||
"tslib": "^2.3.0" | ||
}, | ||
"type": "commonjs", | ||
"main": "./src/index.js", | ||
"typings": "./src/index.d.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,58 @@ | ||
{ | ||
"name": "telegram", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "plugins/telegram/src", | ||
"projectType": "library", | ||
"targets": { | ||
"build": { | ||
"executor": "@nx/js:tsc", | ||
"outputs": ["{options.outputPath}"], | ||
"options": { | ||
"outputPath": "dist/plugins/telegram", | ||
"main": "plugins/telegram/src/index.ts", | ||
"tsConfig": "plugins/telegram/tsconfig.lib.json", | ||
"assets": [ | ||
"plugins/telegram/*.md", | ||
{ | ||
"input": "./plugins/telegram/src", | ||
"glob": "**/!(*.ts)", | ||
"output": "./src" | ||
}, | ||
{ | ||
"input": "./plugins/telegram/src", | ||
"glob": "**/*.d.ts", | ||
"output": "./src" | ||
}, | ||
{ | ||
"input": "./plugins/telegram", | ||
"glob": "generators.json", | ||
"output": "." | ||
}, | ||
{ | ||
"input": "./plugins/telegram", | ||
"glob": "executors.json", | ||
"output": "." | ||
} | ||
] | ||
} | ||
}, | ||
"lint": { | ||
"executor": "@nx/eslint:lint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": [ | ||
"plugins/telegram/**/*.ts", | ||
"plugins/telegram/package.json" | ||
] | ||
} | ||
}, | ||
"test": { | ||
"executor": "@nx/jest:jest", | ||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"], | ||
"options": { | ||
"jestConfig": "plugins/telegram/jest.config.ts" | ||
} | ||
} | ||
}, | ||
"tags": [] | ||
} |
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 @@ | ||
export * from './lib/telegramPlugin' |
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,36 @@ | ||
import { PluginCredential } from 'server/credentials' | ||
|
||
export const pluginName = 'Telegram' | ||
|
||
export const pluginCredentials: PluginCredential[] = [ | ||
{ | ||
name: 'telegram-bot', | ||
serviceType: 'telegram', | ||
credentialType: 'plugin', | ||
initials: 'TBT', | ||
}, | ||
] | ||
|
||
export const TELEGRAM_EVENTS = { | ||
MESSAGE: 'message', | ||
EDITED_MESSAGE: 'edited_message', | ||
CHANNEL_POST: 'channel_post', | ||
EDITED_CHANNEL_POST: 'edited_channel_post', | ||
INLINE_QUERY: 'inline_query', | ||
CHOSEN_INLINE_RESULT: 'chosen_inline_result', | ||
CALLBACK_QUERY: 'callback_query', | ||
SHIPPING_QUERY: 'shipping_query', | ||
PRE_CHECKOUT_QUERY: 'pre_checkout_query', | ||
POLL: 'poll', | ||
POLL_ANSWER: 'poll_answer', | ||
} | ||
|
||
export const TELEGRAM_ACTIONS = { | ||
SEND_MESSAGE: 'sendMessage', | ||
SEND_IMAGE: 'sendImage', | ||
GENERATE_IMAGE: 'generateImage', | ||
} | ||
|
||
export const TELEGRAM_KEY = 'telegramClient' | ||
|
||
export const TELEGRAM_DEVELOPER_MODE = false |
26 changes: 26 additions & 0 deletions
26
plugins/telegram/src/lib/nodes/actions/sendTelegramMessage.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,26 @@ | ||
import { TelegramClient } from '../../services/telegram' | ||
import { EventPayload } from 'packages/server/plugin/src' | ||
import { TelegramEventPayload } from '../../types' | ||
import { SocketDefinition } from '@magickml/behave-graph' | ||
import { TELEGRAM_KEY } from '../../constants' | ||
import { IEventStore } from 'server/grimoire' | ||
|
||
type Inputs = { | ||
Check failure on line 8 in plugins/telegram/src/lib/nodes/actions/sendTelegramMessage.ts GitHub Actions / ESLint
|
||
flow: SocketDefinition | ||
content: SocketDefinition | ||
} | ||
|
||
type Outputs = { | ||
Check failure on line 13 in plugins/telegram/src/lib/nodes/actions/sendTelegramMessage.ts GitHub Actions / ESLint
|
||
flow: SocketDefinition | ||
} | ||
|
||
export const sendTelegramMessage = async ( | ||
dependencies: { [TELEGRAM_KEY]: TelegramClient; IEventStore: IEventStore }, | ||
inputs: { content: string }, | ||
event: EventPayload<TelegramEventPayload> | ||
): Promise<void> => { | ||
await dependencies[TELEGRAM_KEY].getClient().sendMessage({ | ||
text: inputs.content, | ||
chat_id: event.chat.id, | ||
}) | ||
} |
78 changes: 78 additions & 0 deletions
78
plugins/telegram/src/lib/nodes/events/telegramMessageEvents.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,78 @@ | ||
import { | ||
Assert, | ||
NodeCategory, | ||
makeEventNodeDefinition, | ||
} from '@magickml/behave-graph' | ||
import { TELEGRAM_EVENTS } from '../../constants' | ||
import { EventPayload } from 'packages/server/plugin/src' | ||
|
||
type State = { | ||
onStartEvent?: ((event: EventPayload) => void) | undefined | ||
} | ||
|
||
const makeInitialState = (): State => ({ | ||
onStartEvent: undefined, | ||
}) | ||
|
||
export const telegramMessageEvent = makeEventNodeDefinition({ | ||
typeName: 'telegram/onMessage', | ||
label: 'On Telegram Message', | ||
category: NodeCategory.Event, | ||
configuration: { | ||
numInputs: { | ||
valueType: 'number', | ||
defaultValue: 3, | ||
}, | ||
}, | ||
in: {}, | ||
out: { | ||
flow: 'flow', | ||
content: 'string', | ||
event: 'object', | ||
}, | ||
initialState: makeInitialState(), | ||
init: args => { | ||
const { | ||
write, | ||
commit, | ||
node, | ||
engine, | ||
graph: { getDependency }, | ||
} = args | ||
const onStartEvent = (event: EventPayload) => { | ||
write('event', event) | ||
write('content', event.content) | ||
|
||
console.log('event', event) | ||
console.log('content', event.content) | ||
|
||
commit('flow') | ||
|
||
if (!node || !engine) return | ||
|
||
engine.onNodeExecutionEnd.emit(node) | ||
} | ||
|
||
const telegramEventEmitter = getDependency('Telegram') | ||
|
||
telegramEventEmitter?.on('message', onStartEvent) | ||
|
||
return { | ||
onStartEvent, | ||
} | ||
}, | ||
dispose: ({ state: { onStartEvent }, graph: { getDependency } }) => { | ||
Assert.mustBeTrue(onStartEvent !== undefined) | ||
|
||
const telegramEventEmitter = getDependency('Telegram') | ||
|
||
if (onStartEvent) | ||
telegramEventEmitter?.removeListener( | ||
TELEGRAM_EVENTS.message, | ||
onStartEvent | ||
) | ||
|
||
return {} | ||
}, | ||
}) | ||
|
Oops, something went wrong.