Slackbot: how to use the slack channel functions - javascript

I create a slackbot fusing the following from this guide:
var util = require('util');
var path = require('path');
var fs = require('fs');
var SQLite = require('sqlite3').verbose();
var Bot = require('slackbots');
The slackbot I created is basic by replying to keywords and posting messages back in the channel using: this.postMessageToChannel(...)
What I would like is to use functions I see from the slack API such as the ability for the slackbot to leave a channel by itself. The channel.leave function found here in the slack API looks to be able to do this however I am not sure how to get it to work.
How am I able to use this Slack api correctly? Specifically starting with the channel.leave method?

To use any of Slack's API method you need a token. If you followed the instruction from the link you provided you can get your token from the page of installed apps, where you also find your bot.
If will look like this:
Just take the "API Token" and use it in your code to call any of the web methods. If you are unsure how to make an API call in node.js, check out this question.
There is one caveat to your specific problem though. This particular method does not work with a bot token (which is what you got), only with a user token. I don't think it is possible for a bot to leave a channel by itself. Only a real user can do that.

Related

How can I use a secret on Repl.it with my JavaScript code for Telegram using Telegraf?

I have this code:
const bot = new Telegraf('tokengoeshereblablablabla')
And I want it to look like this:
const bot = new Telegraf(TOKEN)
So my Telegram token wont be leaked. I know it's possible, but I don't find it eather here in StackOverflow either Google.
Thanks in advance.
In repl.it you can set your secret variables in specific section
Look at this image below you can set key as TOKEN and value [YOURTOKEN]
Simply you can use it in nodejs file like:
const bot = new Telegraf(process.env.TOKEN)
Note: if you can't access it like above line, you will need to install dotenv package to load environment variables.

How can I make sure that my twitch bot can only take commands from certain users with NODEJS and the TMI API?

I am trying to make a twitch bot that uses a command that only the channel owner can use. How can I identify a unique user. Basically, how can I tell the program to only allow a certain user to use a certain command?
I fixed my issue using the following: ${user['display-name']}
then applied this to a variable and used an if statement.
Like this
var chanName = '${user['display-name']}`;
if (chanName === 'usernameperson`){
stuff;
}

Marvel API and Insomnia (or Postman): how do I pass the hash value that's required?

I'm a relatively new Javascript programmer and I'm experimenting with the Marvel API (I need to access the images for a project) and having a little trouble wrapping my head around the requirements.
As I understand it, you need to pass a hash and a ts (timestamp, I presume), when calling the API from a server-side app. But I don't see in the documentation that this is required when using a client-side app.
I tried to do some basic endpoint testing with Insomnia and I receive the message "You must provide a hash.". Apparently I need the hash for client-side access as well?
I have seen some NodeJS examples that show you how to generate the hash (for example, https://www.raymondcamden.com/2014/02/02/Examples-of-the-Marvel-API), but nothing for the client side (that I could find). I also don't know how I would generate this within Insomnia (or Postman). Any pointers in the right direction would be appreciated.
I'd also like to ask what role the authorized domains play when accessing the Marvel API from a local machine. Do I need to add localhost to this list?
Thanks for any help!
Follow the steps:
Pick an API Endpoint. eg: https://gateway.marvel.com:443/v1/public/characters
Use a query value for ts. ts could be timestamp or any long string.
eg: ts=thesoer
Generate a MD5 hash of ts+privatekey+publickey through code or preferrably online. eg: md5(ts + privKey + pubKey)
For md5 hash: http://www.md5.cz/
Join the dots. URL?ts=val&apikey=key&hash=md5Hash.
eg. https://gateway.marvel.com:443/v1/public/characters?ts=thesoer&apikey=001ac6c73378bbfff488a36141458af2&hash=72e5ed53d1398abb831c3ceec263f18b
Add a pre-requisite script to your postman collection.
var pubkey = "your_public_key";
var pvtkey = "your_private_key";
var ts = new Date().getTime();
pm.environment.set("ts", ts)
pm.environment.set("apikey", pubkey)
var message = ts+pvtkey+pubkey;
var a = CryptoJS.MD5(message);
pm.environment.set("hash", a.toString())
And then you can make your calls like such
https://gateway.marvel.com/v1/public/characters?ts={{ts}}&apikey={{apikey}}&hash={{hash}}
See this collection.
Regarding your authorized domains, add your public IP.

Clarifai client asking for client secret and id

I'm setup my initial js file like so however on build I'm getting an error that the client now requires my client secret and client id .. What's weird is that when I first built my app all initial API requests went through with just the api key. I can see my uploaded + training pictures on the clarifai preview UI so I know they completed successfully. Every call since then has failed though. Not sure where I get the client secret and id since the documentation only provides me with an api key.
// Require the client
const config = require('../config/config');
const Clarifai = require('../../node_modules/clarifai/src');
// initialize with your api key. This will also work in your browser via http://browserify.org/
const app = new Clarifai.App({
apiKey: config['CLARAFAI_API_KEY']
});
As stated on the website...
After creating your API Key, you are ready to make API calls. If you are using a client, authentication will be handled for you. If you are using the REST API, you will need to add the Authorization header as described in the cURL example.
EDIT 7/27/2017:
Screenshot of error msg
As you can see on their authentication post. They have deprecated the client/id and secret and remove them from Nov 15, 2017.
I think you should update your js package.
It will just work fine.

Unable to proceed with Twilio Programmable Video Javascript

I am new to Twilio and facing few problems. I have downloaded twilio programmable video SDK Javascript version for my web app and it works pretty fine however I am unable to figure out how I can enable different users to create conversations and invite people. I want Many to Many relationship and don't know if twilio video supports it or not. Any help would be highly appreciated. Please share any tutorial as well.
Here is the code which i Got from Twilio website for JS/C#
public string generate_token()
{
string AccountSid = "SID";
string ApiKeySid = "APIKEY";
string ApiKeySecret = "APISECRET";
const string ConfigurationProfileSid = "klinik";
// Create an Access Token
var token = new AccessToken(AccountSid, ApiKeySid, ApiKeySecret);
// Set the Identity of this token
token.Identity = "example-user";
// Grant access to Conversations
var grant = new ConversationsGrant();
grant.ConfigurationProfileSid = ConfigurationProfileSid;
token.AddGrant(grant);
return token.ToJWT().ToString();
// Serialize the token as a JWT
// Console.WriteLine(token.ToJWT());
}
I am getting the following error on .ToJWT function in visual studio:
Error CS0012 The type 'JwtHashAlgorithm' is defined in an assembly that is not referenced. You must add a reference to assembly 'JWT, Version=1.3.3.0, Culture=neutral, PublicKeyToken=null'.
Twilio developer evangelist here.
It's difficult to help you any further as you haven't shared any code or anything you've tried.
The JavaScript quickstart is the best example of how to get started with the Video SDK. I recommend taking a look through the code to see how it is built.
To make many to many conversations, you just need to invite another user to an existing conversation or invite many users at one time. Make sure you invite them from all the existing participants as this is a peer to peer connection, so every user needs to create a connection with every other user. For that reason, it's not recommended to make many to many conversations of more than 4 people total (though you should test to see what kind of results you get).
Let me know if that helps at all.

Categories

Resources