Skip to content

Commit

Permalink
Merge pull request #25 from AdarshNaidu/unread-messages-and-mentions-…
Browse files Browse the repository at this point in the history
…intents

New Intents | Name Resolution | Intent Confirmation | Local Development | Interaction Model Update | AWS Lambda setup
  • Loading branch information
Sing-Li authored Aug 30, 2020
2 parents ffe765c + 82581a8 commit eecdbc3
Show file tree
Hide file tree
Showing 14 changed files with 2,844 additions and 600 deletions.
53 changes: 52 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,43 @@ Function URL (factsAboutGoogle): https://us-central1-myprojectname-ab123.cloudfu

22. Finally We Are Done !

#### AWS Lambda Deployment
The fulfillment code can also be deployed in AWS as a lambda function as an alternative to using Firebase.

1. Navigate to the AWS Lambda console.


2. Create a new function with the following settings.
+ Author From Scratch
+ Runtime: Node.js 12.x
+ Permissions: Create a new role with basic Lambda Permissions


3. Add the following Environment Variables
```
OAUTH_SERVICE_NAME => Name of the Custom OAuth service created in Rocket Chat OAuth Settings
SERVER_URL => Rocket Chat server url (https://YOUR.SERVER.chat)
```

4. Add an API Gateway trigger with the following settings.
+ Create an API
+ API Type: HTTP API
+ Security: Open

5. Copy the following value somewhere.
+ Click on API Gateway > Details > API endpoint

6. Navigate to Dialogflow > Fulfillment section: https://dialogflow.cloud.google.com/#/agent/project_id/fulfillment
+ Paste the API endpoint in the Webhook URL field.

7. To upload the backend code in Lambda function
+ Navigate to `./functions` directory in the project repository
+ Select all files and compress into a zip file.
+ In the **Functions Code** section of AWS Lambda Function
+ Actions > Upload a .zip file
+ Select the compressed zip file
+ Click **Save**.

---

## Running this Action
Expand All @@ -218,7 +255,21 @@ Function URL (factsAboutGoogle): https://us-central1-myprojectname-ab123.cloudfu

---

## Development
## Development

#### Local Development Setup
The project can be run on local development for debugging. The steps are listed below.
1. Create an environment file inside the functions folder.
+ `./functions/.env`
2. Add the following variables
```
SERVER_URL=<your server url>
OAUTH_SERVICE_NAME=<custom OAuth service name>
```
3. Start the server locally by running `npm run local`
4. Create a tunnel using ngrok `ngrok http 3000`
5. Navigate to Dialogflow > Fulfillment section: https://dialogflow.cloud.google.com/#/agent/project_id/fulfillment
+ Paste the URL generated by ngrok in the Webhook URL field.

#### Files
1. `./functions/index.js`
Expand Down
Binary file modified agent.zip
Binary file not shown.
14 changes: 14 additions & 0 deletions functions/apiEndpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ module.exports = {
deletechannelurl: `${ SERVER_URL }/api/v1/channels.delete`,
postmessageurl: `${ SERVER_URL }/api/v1/chat.postMessage`,
channelmessageurl: `${ SERVER_URL }/api/v1/channels.messages?roomName=`,
immessageurl: `${ SERVER_URL }/api/v1/im.messages`,
imcountersurl: `${ SERVER_URL }/api/v1/im.counters`,
groupmessageurlname: `${ SERVER_URL }/api/v1/groups.messages?roomName=`,
channelmentionsurl: `${ SERVER_URL }/api/v1/channels.getAllUserMentionsByChannel?roomId=`,
channelinfourl: `${ SERVER_URL }/api/v1/channels.info?roomName=`,
userinfourl: `${ SERVER_URL }/api/v1/users.info?username=`,
Expand All @@ -23,6 +26,7 @@ module.exports = {
addownerurl: `${ SERVER_URL }/api/v1/channels.addOwner`,
archivechannelurl: `${ SERVER_URL }/api/v1/channels.archive`,
counterurl: `${ SERVER_URL }/api/v1/channels.counters?roomName=`,
channelcountersidurl: `${ SERVER_URL }/api/v1/channels.counters?roomId=`,
inviteuserurl: `${ SERVER_URL }/api/v1/channels.invite`,
leavechannelurl: `${ SERVER_URL }/api/v1/channels.leave`,
kickuserurl: `${ SERVER_URL }/api/v1/channels.kick`,
Expand Down Expand Up @@ -56,5 +60,15 @@ module.exports = {
groupannouncementurl: `${ SERVER_URL }/api/v1/groups.setAnnouncement`,
unarchivegroupurl: `${ SERVER_URL }/api/v1/groups.unarchive`,
groupmessageurl: `${ SERVER_URL }/api/v1/groups.messages?roomId=`,
groupmessagenameurl: `${ SERVER_URL }/api/v1/groups.messages?roomName=`,
groupcounterurl: `${ SERVER_URL }/api/v1/groups.counters?roomId=`,
groupcounternameurl: `${ SERVER_URL }/api/v1/groups.counters?roomName=`,
channellisturl: `${ SERVER_URL }/api/v1/channels.list.joined`,
grouplisturl: `${ SERVER_URL }/api/v1/groups.list`,
getsubscriptionsurl: `${ SERVER_URL }/api/v1/subscriptions.get`,
getmentionedmessagesurl: `${ SERVER_URL }/api/v1/chat.getMentionedMessages`,
imlisturl: `${ SERVER_URL }/api/v1/im.list`,
getrolesfromchannelurl: `${ SERVER_URL }/api/v1/channels.roles`,
getrolesfromgroupurl: `${ SERVER_URL }/api/v1/groups.roles`,
setstatusurl: `${ SERVER_URL }/api/v1/users.setStatus`,
};
31 changes: 24 additions & 7 deletions functions/config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
// Environment Variables
const functions = require('firebase-functions');

module.exports = {
SERVER_URL : functions.config().envariables.server_url,
CLIENT_ID : functions.config().envariables.clientid,
OAUTH_SERVICE_NAME : functions.config().envariables.oauth_service_name
};
if (process.env.DEVELOPMENT) {
// if code is running in local
require('dotenv').config();
module.exports = {
SERVER_URL: process.env.SERVER_URL,
CLIENT_ID: process.env.CLIENT_ID,
OAUTH_SERVICE_NAME: process.env.OAUTH_SERVICE_NAME
}
} else if(Boolean(process.env['AWS_LAMBDA_FUNCTION_NAME'])) {
// if code is deployed in aws lambda function
module.exports = {
SERVER_URL: process.env.SERVER_URL,
CLIENT_ID: process.env.CLIENT_ID,
OAUTH_SERVICE_NAME: process.env.OAUTH_SERVICE_NAME
}
} else {
// if code is deployed in firebase function
const functions = require('firebase-functions');
module.exports = {
SERVER_URL : functions.config().envariables.server_url,
CLIENT_ID : functions.config().envariables.clientid,
OAUTH_SERVICE_NAME : functions.config().envariables.oauth_service_name
};
}
Loading

0 comments on commit eecdbc3

Please sign in to comment.