Unverified Commit e114fbb4 authored by SingLi's avatar SingLi Committed by GitHub

Merge pull request #1 from PrajvalRaval/master

Initial commit
parents 87966cd0 b598b78e
# alexa-news-publisher
Innovative voice UI experience powered by Rocket.Chat for the Alexa ecosystem.
# Alexa News Pulisher
Flash Briefing Skill - Powered By Rocket.Chat
# Let's Get Started
Deploy your Flash briefing skill in minutes using Rocket chat and broadcast messages on both channel and skill in realtime.
# Setup
### Pre-requisites
* Node.js (> v8.10)
* Register for an [Amazon Developer Account](https://developer.amazon.com/)
* Rocket Chat Server updated to Release 1.2.0-rc.0 or later.
### Enabling Anonymous Read
* Go to **Server** -> **Three Dot Menu** -> **Administration** -> **Accounts** , and Set **Allow Anonymous Read** to **True**.
**Note:** Requires Admin Access.
### Creating A Main Broadcast Channel
* On Server Homepage click on **Create New** -> **Channel**
* Set **Private Channel** -> **Public Channel** and Enable **Broadcast Channel**.
* Then give your **Channel Name**, and click on **Create**.
* This channel will work as the main channel that tells your flashbriefing from where to gather messages. Make sure you the channelnames in this channel are declared in following way:
### Deploying Code
* Clone the repository contents to your server.
* After cloning create a **.env** file with following environment variables:
* **PORT** : Enter The Port number you want server to run on.
* **CHANNEL_NAME** : Enter the name of the broadcasting channel we created earlier. Make sure its in lower case with no spaces.
* **SERVER_URL** : Enter your current Rocket.Chat server url here. Ex- https://your.sever.chat
* Change **cacheTimeout** & **flashBriefingTitle** from **index.js** as per your requirement.
* **cacheTimeout** : It is the frequency of your message update. For example if you want your flash briefing to update data every hour then set the value of cacheTimeout to `3600000` i.e one hour in milliseconds.
* **flashBriefingTitle** : The title of the feed item to display in the Alexa app.
* Deploy the code to the server of your choice along.
* Make sure it's working on an **HTTPS** domain if not then assign a **HTTPS** domain to it.You can then test your server by sending `/ping` or `/download` request.
* After App is deployed we will be using **URL/Domain** of the server in the next step.
### Creating Flash Briefing Skill
* Go [Alexa Developer Console](https://developer.amazon.com/alexa/console/ask).
* Click on **Create Skill**, give **Skill name** , **Default language** and choose **Flash Briefing** model then click on **Create Skill**.
* Write **Custom Error Message**, then click on **Add new feed**. Fill details as per you requirement.
* Choose **Content type** as **Text**.
* In **Feed**, paste the **URL/Domain**.
* Upload Photo and hit **Add**.
* Click on **Save** and that should complete the complete the process.
## Usage
* Flash briefing will use the **channel names in last message** from the main broadcast channel for broadcasting. It will then gather all the messages from the mentioned channels and present it to the user in the skill.
* Make sure that the last message is a **text message**.
Need community help in the following:
* add a conversation flow to allow an admin to "publish the briefing" daily using the VUI
const express = require("express");
const axios = require('axios');
const app = express();
const cache = require('memory-cache');
// Environment Variables
const PORT = process.env.PORT || 3000;
const serverurl = process.env.SERVER_URL;
const channelName = process.env.CHANNEL_NAME;
// Title Text & News Update Frequency
const flashBriefingTitle = 'Rocket Chat Flash Briefing';
const cacheTimeout = 300000;
// Altenative End Lines
var climaxLinesArray = ["Finally", "And just to wrap up", "And last but not least"];
// Get Date And UID
async function getDateUID() {
const now = new Date();
const jsonDate = now.toJSON();
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
var length = 7;
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
return {
date: jsonDate,
uid: result
// Get Channel Names
const getSourceChannels = async (channelnamei) =>
await axios
.get(`${ serverurl }/api/v1/channels.anonymousread?roomName=${ channelnamei }`)
.then((res) => res.data)
.then((res) => `${ res.messages[0].msg }`)
.catch((err) => {
const getChannelLastMessage = async (channelnamei) =>
await axios
.get(`${ serverurl }/api/v1/channels.anonymousread?roomName=${ channelnamei }`)
.then((res) => res.data)
.then((res) => `${res.messages[0].msg}`)
.catch((err) => {
const getMessages = async () => {
var channelNamesString = await getSourceChannels(channelName);
var messagearray = [];
var array = channelNamesString.split("#");
var randomNumber = Math.floor((Math.random() * climaxLinesArray.length));
console.log('THIS IS A RANDOM NUMBER' + randomNumber);
for (let i = 1; i < array.length; i++) {
console.log(array[i] + i);
const channel = array[i];
const lastMessage = await getChannelLastMessage(channel);
if (array.length != 2 && i === array.length - 1) {
var channelResponse = `${climaxLinesArray[randomNumber]} From ${channel} - ${lastMessage}`;
} else {
var channelResponse = `From ${channel} - ${lastMessage}`;
var responseString = messagearray.join('. ');
return responseString;
app.get('/ping', (req, res) => {
console.log('PING Request');
const pongData = ('{"data":"PONG"}');
var pong = JSON.parse(pongData);
return res.status(200).send(pong);
app.get('/', async (req, res) => {
if (cache.get('message')) {
console.log('Using Cached Data From Memory');
const resultJSON = JSON.parse(cache.get('message'));
return res.status(200).send(resultJSON);
} else {
console.log('Getting New Data From Rocket Chat Server');
var date_uid = await getDateUID();
var messages = await getMessages();
var responseJSON = JSON.stringify({
uid: date_uid.uid,
updateDate: date_uid.date,
titleText: flashBriefingTitle,
mainText: messages,
redirectionUrl: serverurl
console.log('Storing Data In Memory.')
cache.put('message', responseJSON, cacheTimeout);
var finalResponse = JSON.parse(responseJSON);
return res.status(200).send(finalResponse);
app.listen(PORT, '', function () {
console.log(`Server Now Listening on Port ${PORT}`);
"name": "rceditorialfb",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
"author": "Prajval Raval",
"license": "ISC",
"dependencies": {
"axios": "^0.19.0",
"dotenv": "^8.0.0",
"express": "^4.16.4",
"memory-cache": "^0.2.0"
"engines": {
"node": "v11.3.0"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment