0.1.6 • Published 3 years ago

synology-chat-incoming-webhook v0.1.6

Weekly downloads
5
License
MIT
Repository
github
Last release
3 years ago

Synology Chat Incoming Webhook integration

This package helps with sending files to your Synology Chat. It uses the incoming webhook integration. This integration will provide you with an URL that allows the program to interact with a single channel. To upload local files, the package will open up a webserver that will server the files from a temporary directory under a random file name.

Usage

The easy way:

const { createSynoChatFileService } = 'synology-chat-incoming-webhook'
const chat = createSynoChatFileService();

// text
await chat.send("Sending a test message");

// local file
await chat.send({
	text: "Sending a test file",
	filePath: "c:\\temp\\my-file.txt"
});

// remote file
await chat.send({
	text: "Sending a file url",
	fileUrl: "https://keestalkstech.com/wp-content/uploads/2020/08/photo-1577138967570-266667b3deed-1200x675.jpg"
});

// memory buffer
let buffer = Buffer.from("Hello world!", 'utf-8');
await chat.send({
	text: "Seding a buffer",
	buffer: buffer,
	bufferExtension: ".txt"
});

It will get the configuration from your environment variables or infer them:

VariableDefaultNotes
SCIWI_FILE_SERVER_PORT8033
SCIWI_FILE_SERVER_BASE_URLlocal iptries to scan your network interfaces
SCIWI_SYNOLOGY_CHAT_INCOMING_URLsee token section

Advanced

Create and configure you own service:

const { SynoChatFileService } = 'synology-chat-incoming-webhook'
const chat = new SynoChatFileService(
	8033,
	"http://192.168.1.13:8033",
	"{http or https}://{url or ip}/webapi/entry.cgi?api=SYNO.Chat.External&method=incoming&version=2&token=%22{your-token}%22"
)

Or don't use the file server:

const { SynoChatService } = 'synology-chat-incoming-webhook'
const chat = new SynoChatService(
	"{http or https}://{url or ip}/webapi/entry.cgi?api=SYNO.Chat.External&method=incoming&version=2&token=%22{your-token}%22"
)

If you want to use multiple channels:

const { Channel, MultiChannelSynoChatFileService } = 'synology-chat-incoming-webhook'
const channels = [
	new Channel("General", "{http or https}://{url or ip}/webapi/entry.cgi?api=SYNO.Chat.External&method=incoming&version=2&token=%22{your-token}%22"),
	new Channel("Random",  "{http or https}://{url or ip}/webapi/entry.cgi?api=SYNO.Chat.External&method=incoming&version=2&token=%22{your-token}%22"),
]

const chat = new SynoChatService(channels, 8033, "http://192.168.1.13:8033");

await chat.send("General", "Hellow!");
await chat.send("Random", {
	text: "Sending a file url",
	filePath: "c:\\temp\\my-file.txt"
});

How to get an incoming webhook

To the following:

  • Open up the DSM of your Synology NAS
  • Open the Main Menu and click on Synology Chat
  • Click on your user icon in the top right corner.
  • Click on Integration
  • Click on Incoming Webhooks
  • Click on the Create button
  • Finish the dialog and copy the Webhook URL
  • Add this URL as SCIWI_SYNOLOGY_CHAT_INCOMING_URL environment variable to your application.

Local File Server

When sending a local file or a memory buffer, the following happens:

  • When a local file or buffer is send to the chat, an express web server is started. It serves static files from a new temporary directory.
  • The local file or buffer is copied to a new file in the temporary directory with a random file name.
  • The URL is send to Synology. Synology will download the file from the web server.
  • When the server is stopped, the directory will be deleted as well.
0.1.6

3 years ago

0.1.4

3 years ago

0.1.5

3 years ago

0.1.3

3 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.0.23

4 years ago

0.0.22

4 years ago

0.0.20

4 years ago

0.0.21

4 years ago

0.0.19

4 years ago

0.0.18

4 years ago

0.0.17

4 years ago

0.0.16

4 years ago

0.0.15

4 years ago

0.0.14

4 years ago