Hubot Message Only Specific Channel On Enter/Leave - coffeescript

Working on creating a list of messages that Hubot can randomly choose from to display in the #general channel when someone joins the company. I've got the message part working, but it's doing it on ANY channel... how can I limit it to just a specific channel? One step further, would like to take the users name who entered and paste it inside the sentences if possible.
Thanks!
validWelcome = [
'We have a new kid on the block, Hello!'
'Welcome the newest member to the team!'
'Thanks for joining us!'
'Happy to have you here!'
]
module.exports = (robot) ->
robot.enter (msg) ->
msg.send {room: '#integration-test'}, msg.random validWelcome

There are two issues to consider
Does the chat software you are using expose enough information to Hubot via the adapter when a user joins a room (see docs)
Do you want to display this message if someone leaves and re-joins the #general room?
Taking a wild guess that you are using Slack you can see what the Slack adaptor sends you here. You really want access to channel.name but you can get channel.id from msg.room and take it from there and solve #1. If you're not using Slack find the source for your adapter and search for EnterMessage.
If you want to solve #2 you'll need to do something clever with Hubot's brain and record the fact that you've sent a welcome for each user.

Related

Thunderbird WebExtensions / MailExtensions development - How to deal with events such as "new mail"?

I'm trying to write my very first Thunderbird extension. If possible, I'd like to only use the newer WebExtensions / MailExtensions APIs.
Two things my extension needs to do:
Performs an action when a new mail arrives and is not junk.
When a message is read, check if there are still unread messages and, if not, performs an action.
The only examples I've found online dealing with "new mail event" hooks look like there are not using the newer APIs. For example:
Components.classes["#mozilla.org/messenger/msgnotificationservice;1"]
.getService(Components.interfaces.nsIMsgFolderNotificationService);
notificationService.addListener(myListener, notificationService.msgAdded);
or
Components.classes['#mozilla.org/messenger/services/session;1']
.getService(Components.interfaces.nsIMsgMailSession)
.AddFolderListener(myListener, Components.interfaces.nsIFolderListener.all);
... where myListener would be called when a new email arrives.
Those codes generate the error Components.classes is undefined in Thunderbird 91. If I understand properly this is because more stuff is required to stay compatible with the legacy API.
My question:
What is the proper way to listen to a new email event, using the WebExtensions / MailExtensions APIs?
Links I did read (but maybe I missed something!):
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Developing_WebExtensions_for_Thunderbird
https://webextension-api.thunderbird.net/en/91/
Oh! I found it!
background.js :
browser.messages.onNewMailReceived.addListener((folder, messages) => {
// ...
});
Those permissions are required: messagesRead and accountsRead.

Google action builder/Google assitant How to use proper noun as type

i would like to have a type that represent proper nom, such as family name for exemple but i can't find anything on this.
My goal is to send a info to an other personne using google assistant and my backend.
For exemple the user can say "Send this info to john smith" the info is stored in my backend so i have no problem finding and i got the id of the personne who is talking to the google assistant so this is no problem either.
The problem is how can i get john smith as a parameter that i send to my webhook? So my backend can verify the user list in my database and send the info if the user existe. I tried to use Type but a family doesn't match any pattern because it's can be anything...
If anyone know how to use google action builder with proper noun i would be grateful to know how i can manage to do it.
You have generally two options.
Free form text approach
First you can create a "Free form text" type which can catch pretty much anything being said.
Then a custom intent can be trained with a few examples to pull out the correct proper noun (or anything else). Your webhook will be able to match at that point.
Type Overrides approach
Alternatively, you can create a new type that starts with a preset of sample names that you use in your custom intent. Then, when the action starts, you can get the user's personal contact list in the webhook and set session type overrides.
Here's an example of the code I got from a music player action:
conv.session.typeOverrides = [{
name: 'genre',
mode: Mode.TypeReplace,
synonym: {
entries: Array.from(trackGenres).map(genre => ({
name: genre,
synonyms: [genre]
}))
}
}]
Depending on your system architecture, one of these may make more sense than the other. The first is better at capturing everything, but may require more post-processing on your webhook. The latter is better at precision, but may mean names may not match if they don't match entirely.

How to give personalised greeting in Watson Conversation?

While Defining the Dialog in the Watson Conversation I'm not able to greet user with his/her name or I'm not able to detect contact number sent by the user and rephrase it to the user. Is it possible to do it in the Watson Conversation Api or not.
Although Mitch's response is correct, here is an example of doing a personalised response.
1. Set your conversation_start node text to "Hello <? context.username ?>".
2. In your code you would do something like this (Python).
import json
from watson_developer_cloud import ConversationV1
conversation = ConversationV1(
username='SERVICE_USERNAME',
password='SERVICE_PASSWORD',
version='2016-07-11')
workspace_id = 'WORKSPACE_ID_CONVERSATION'
response = conversation.message(workspace_id=workspace_id, context= {'username':'Simon'})
print json.dumps(response)
3. When you run this, it should output the following, with the "text" part being what the user sees.
{
"entities":[],
"intents":[],
"output":{
"log_messages":[],
"nodes_visited":["node_1_1472298724972],
"text":["Hello Simon"]
},
"context":{
"username":"Simon",
"conversation_id":"9dc1501b-ac53-4b51-a299-37f5314ebf89",
"system":{
"dialog_turn_counter":1,
"dialog_stack":["root"],
"dialog_request_counter":1
}
},
"input":{}
}
One thing to be aware is that, the context object is used to maintain the state of the conversation. So if you plan to use just REST API's then you need to merge your context variables into the preceding context object before sending it. You do only need to do this at points where you do know the conversation needs that context.
Do you already have access to this information? You can send these values through as context, and refer to them using $context_variable
The same goes for collecting information from a user. You can capture things using regular expressions via your application, or using some Spring Expressions, you can see the text.matches here:
https://www.ibm.com/watson/developercloud/doc/conversation/dialog_reference.shtml
You would store this as context, and then refer to it using $context_variable again.
Information like names and phone numbers is quite open ended, so can be difficult to capture without using an open entity extraction engine, which we are researching best ways to incorporate this.
To get the user's input, use:
"context": {"yourVariable": "<?input.text?>"}
And to show:
"output": {"text": "You entered this $yourVariable"}

How to intercept/hook into Hubot responses

Is there any way to intercept all Hubot triggers/response globally? The interception should be able to inspect, modify, forward, or reject Hubot response before being sent.
Some goals I would like to achieve:
Throttle all message sent by Hubot (from all plugins/scripts) to prevent flooding.
Apply some kind of ACL (Access Control List) to limit who can use a command.
etc.
I cannot find it in the official Hubot documentation. Am I missing some things?
For controlling access to listeners, check out listener middleware: https://hubot.github.com/docs/scripting/#listener-middleware
https://hubot.github.com/docs/patterns/#restricting-access-to-commands
For rate limiting command execution, check out hubot-rate-limit: https://github.com/michaelansel/hubot-rate-limit
For controlling responses, keep an eye on the response middleware PR: https://github.com/github/hubot/pull/1021
this is a simple middleware I wrote to log messages that are directed at the robot. it can easily be modified to do something else depending on the user name or room name or whatever.
module.exports = (robot) ->
robot.listenerMiddleware (context, next, done) ->
#create a regex with the robots name in it
robotName = new RegExp("#{context.listener.robot.name}", "i")
#only log messages meant for the robot
if robotName.test("#{context.response.message.text}")
#only log messages once with the "everything" listener context
if context.listener.regex.source is /(.+)/i.source
console.log "User: #{context.response.message.user.name} asked me to \"#{context.response.message.text}\" in Channel: #{context.response.message.room}"
#your code goes here
next()
this thing will allow you to rate limit

Drupal: How to automatically send (cck) node content + file attachment via email

I am still quite new to Drupal and have very limited programming skills.
I am trying to build a job board site using cck + views. I have created 2 related content types: a "job post" and a "job application" - both are related using a nodereference field.
The job application node has 4 fields: id of the job post to which the person is applying, email of the applicant, cover letter (body field) and attached cv (cck field that allows users to attach/upload a document).
Question: Once a job application is created I would like the content of the node (including the attached file) to be automatically sent via email to the person who posted the job (destination email address is in a cck field in the related "job post" node).
Thus my requirements are: (1) to automtically "transfer" the destination email address from the "job post" content type to the "job application" content type; and (2) to automatically send all the "job application" node contents + file attachment to the destination email.
Is there any module that can help me achieve this?
Thank you so much for your support.
My email address is: wedge.paul#gmail.com
To give it to you straight: No, there is no module that will do this. Largely because you have already made most content types and it is pretty unique to your project.
Still, you may not have limited programming skill, I would advice learning it when working with drupal. What you are asking is really not that hard to create by writing a custom module. Writing a custom module is really not that hard, and starting to write a custom module in Drupal is really well documented.
I can tell you what to use in the custom module, however it is better if you create it yourself (for future projects).
So you create your custom module:
function mymod_nodeapi{ //here all the action happens when a node is created
switch ($op) {
//if the node is inserted in the database
case 'insert':
//if node is a job application
if($node->type = "jobapplication"){
//using node_load function, you can load other nodes in a variable
$relatednode = node_load($node->nodereference);
//using drupal_mail function, you can mail people
drupal_mail();
}
break;
}
}
This code has not been tested and can't be copy pasted. However node_load and drupal_mail as well as hook_nodeapi... use those functions and you'll get there.
Lullabot's video tutorial "Learning CCK for Drupal" is based on the concept of a job application/posting site as a case study. It may be worth investigating.
no, I'm not connected in any way to Lullabot; just a fellow Drupaler