strophe to register user on ejabberdctl - xmpp

I would like to add a user on ejabberd server using strophe with out typing ejabberdctl register uname servename passwd at command prompt. Is it possible to implement?. Is there any
XMPP protocol exists to register an user?
Thanks
Sathi

Yes it is possible... you need to allow for inline registration on the server. Once that's done, you can certainly do it from any client or client library, include strophe.js.

Use mod_admin_extra and mod_rest then you get a full restfull access to jabberctl + some extra commands. Search the module documentation for more information on how to set this up.

I am using strophe.register.js
$("#register").click(function () {
var connect = new Strophe.Connection('http://yourserver.com/http-bind');
var callback = function (status) {
if ( status === Strophe.Status.REGISTERING ) {
console.log('REGISTERING')
}
else if ( status === Strophe.Status.REGIFAIL ) {
console.log('REGIFAIL')
}
else if ( status === Strophe.Status.REGISTER ) {
console.log('REGISTER')
connect.register.fields.username = "joe"
connect.register.fields.password = "doe"
connect.register.submit();
}
else if ( status === Strophe.Status.SUBMITTING ) {
console.log('SUBMITTING')
}
else if ( status === Strophe.Status.SBMTFAIL ) {
console.log('SBMTFAIL')
console.log('Something went wrong...');
}
else if ( status === Strophe.Status.REGISTERED ) {
console.log('REGISTERED')
console.log('Your account has been created successfully and is ready to use!');
}
}
connect.register.connect("yourserver.com", callback);
});

Related

ionic3+firebase+angularfire2 facebook email null with Multiple accounts per email address

In my firebase dashboard I have set multiple accounts for one email option.
firebase dashboard
The configuration of Angularfire2 is the standard so I do not hit the code of app.modules.ts
home.ts
facebookir(){
let goPagePrehome:boolean = false;
let userDB:any;
firebase.auth().signInWithPopup(new firebase.auth.FacebookAuthProvider())
.then(res => {
console.log(res);
console.info(JSON.stringify(res));
this.userService.getUsers()
.forEach((users) => {
users.forEach((user) =>{
if(user['user_email'] == res.additionalUserInfo.profile.email){
// console.log('res.additionalUserInfo.profile.email');
// console.log(user);
userDB = user;
goPagePrehome= true;
}
});
if(goPagePrehome){
this.goNextPagePrehome(userDB);
}else{
this.singup();
}
});
}); }
In the previous code, the user's email is created and verified in our database. And is sent to the record "this.singup ();" Or to the home "this.goNextPagePrehome (userDB);"
sign.ts
this.afAuth.authState.subscribe( user => {
console.log('find user facebook 2');
console.log(user);
if (user){
if(user.providerData["0"].providerId == "facebook.com"){
if(this.userData['picture'] == '' || this.userData['picture'] == undefined || this.userData['picture']== null){
console.info('find user facebook 2 - si');
this.userData['name']=this.userData['username']= user.providerData["0"].displayName;
this.userData['email']= user.providerData["0"].email;
this.userData['picture']= user.providerData["0"].photoURL;
console.log(this.userData);
}
}
//this.envioCorreoFacebook();
} else {
console.info('find user facebook 2 - no');
}
});
As you can see in both files I am verifying the mail for the data supplied by the provider as "providerData [" 0 "]" and "res.additionalUserInfo.profile.email".
The firebase response is:
firebase images
I need your help to correct this problem that some facebook accounts work with firebase.?
I got the mail again; although by default it should bring it to all facebook accounts.
var provider = new firebase.auth.FacebookAuthProvider();
provider.addScope('email');
firebase.auth().signInWithPopup(provider)
.then(res => {...});

How to use botkit with facebook and wit.ai

I am a novice in chatbot development and I would like some help.
While it seems quite simple to connect botkit with facebook messenger and wit.ai in orger to use NLP. I haven't managed to do so. My initial goal is to have a simple conversation like hello-hello but using wit.ai as middleware.
Below I attach the code. What it should do is receive a "hello" message, pass it to wit.ai and then respond "I heard hello!" as a reply (without using wit at this stage). Instead I just receive
debug: RECEIVED MESSAGE
debug: CUSTOM FIND CONVO XXXXXXXXXXXXXX XXXXXXXXXXXXXX
debug: No handler for message_received
after every message I send to facebook messenger bot. In wit it seems like I am getting the messages since I receive messages in my inbox to update the intents.
If there is any code much simpler than the one below I would be very happy to have it so that I can start with something much simpler :).
Thanks
<pre><code>
if (!process.env.page_token) {
console.log('Error: Specify page_token in environment');
process.exit(1);
}
if (!process.env.page_token) {
console.log('Error: Specify page_token in environment');
process.exit(1);
}
if (!process.env.verify_token) {
console.log('Error: Specify verify_token in environment');
process.exit(1);
}
if (!process.env.app_secret) {
console.log('Error: Specify app_secret in environment');
process.exit(1);
}
var Botkit = require('./lib/Botkit.js');
var wit = require('./node_modules/botkit-middleware-witai')({
token: process.env.wit,
minConfidence: 0.6,
logLevel: 'debug'
});
var os = require('os');
var commandLineArgs = require('command-line-args');
var localtunnel = require('localtunnel');
const ops = commandLineArgs([
{name: 'lt', alias: 'l', args: 1, description: 'Use localtunnel.me to make your bot available on the web.',
type: Boolean, defaultValue: false},
{name: 'ltsubdomain', alias: 's', args: 1,
description: 'Custom subdomain for the localtunnel.me URL. This option can only be used together with --lt.',
type: String, defaultValue: null},
]);
if(ops.lt === false && ops.ltsubdomain !== null) {
console.log("error: --ltsubdomain can only be used together with --lt.");
process.exit();
}
var controller = Botkit.facebookbot({
debug: true,
log: true,
access_token: process.env.page_token,
verify_token: process.env.verify_token,
app_secret: process.env.app_secret,
validate_requests: true, // Refuse any requests that don't come from FB on your receive webhook, must provide FB_APP_SECRET in environment variables
});
var bot = controller.spawn({
});
controller.setupWebserver(process.env.port || 3000, function(err, webserver) {
controller.createWebhookEndpoints(webserver, bot, function() {
console.log('ONLINE!');
if(ops.lt) {
var tunnel = localtunnel(process.env.port || 3000, {subdomain: ops.ltsubdomain}, function(err, tunnel) {
if (err) {
console.log(err);
process.exit();
}
console.log("Your bot is available on the web at the following URL: " + tunnel.url + '/facebook/receive');
});
tunnel.on('close', function() {
console.log("Your bot is no longer available on the web at the localtunnnel.me URL.");
process.exit();
});
}
});
});
controller.middleware.receive.use(wit.receive);
controller.hears(['hello'], 'direct_message', wit.hears, function(bot, message) {
bot.reply(message, 'I heard hello!');
});
function formatUptime(uptime) {
var unit = 'second';
if (uptime > 60) {
uptime = uptime / 60;
unit = 'minute';
}
if (uptime > 60) {
uptime = uptime / 60;
unit = 'hour';
}
if (uptime != 1) {
unit = unit + 's';
}
uptime = uptime + ' ' + unit;
return uptime;
}
Make sure you have a few conversations in Wit.ai beforehand so for example hello there and highlight the hello in that statement as something like, greetings.
Now i'm not sure what your intents are called in wit.ai but in your statement controller.hears(['hello'] you're actually listening to the wit.ai intents. So in the example i mentioned above, we'd be using hears(['greetings']) since that's the intent in wit.ai.
Also, instead of using direct_message use message_received this is what it should look like:
controller.hears(['hello'], 'message_received', wit.hears, function(bot, message) {
bot.reply(message, 'I heard hello!');
});
If you're struggling tracking down the problem you can stick a console statement in your controller so something like console.log("Wit.ai detected entities", message.entities); and see what you get back from that.
Let me know if you're still having any issues :)

CORONA SDK - facebook.showDialog() appears and disappears after a while

I've added Facebook to my application.
The login is ok, except that facebook.login() opens the browser instead of the native Facebook App, but then, when I call Facebook.showDialog() the popup pops up, but after a second or two it disappears.
Note that I get this behavior on iOS only, while on Android it is working fine.
I'm using the code below in my game.lua file:
local function facebookListener( event )
if ( "session" == event.type ) then
if ( "login" == event.phase ) then
local access_token = event.token
facebook.showDialog( "feed", { name = "SuperCool Game Coming soon", description = "Trying to figure out how to get my game to rule the world.", picture = "http://omnigeekmedia.com/wp-content/uploads/2011/05/omniblaster_promo-300x300.png", link = "http://www.omnigeekmedia.com/"})
end
elseif ( "request" == event.type ) then
print("facebook request")
if ( not event.isError ) then
local response = json.decode( event.response )
end
elseif ( "dialog" == event.type ) then
print( "dialog", event.response )
end
end
fbAppID = "my app ID" --replace with your Facebook App ID
function logOnFacebook(event)
if(event.phase=="ended")then
facebook.login( fbAppID, facebookListener, { "user_friends", "publish_actions" } )
end
end
["facebook"] =
{
publisherId = "com.coronalabs",
supportedPlatforms = { iphone = true, ["iphone-sim"] = true },
},
I'm running on build 2015.2729.
How can I manage to get Facebook work?
I would suggest updating to the v4 version of the plugin. While it's technically still in beta, it's required for iOS 9 builds. See:
https://coronalabs.com/blog/2015/07/24/facebook-v4-plugin-android-beta/
https://coronalabs.com/blog/2015/09/01/facebook-v4-plugin-ios-beta-improvements-and-new-features/
Browsing through the source code of the old Facebook plugin, this error will occur in the event that a permission requested wasn't granted!
In the source code for the old Facebook plugin, this can be seen in the FBSessionReauthorizeResultHandlers.
for ( int i = 0; i < [publishPermissions count]; i++)
{
if ( ![publishSession.permissions containsObject:[publishPermissions objectAtIndex:i]] )
{
release = true;
publishError = [[NSError alloc] initWithDomain:#"com.facebook" code:123 userInfo:nil];
break;
}
}
This will also occur for read permissions that were requested and not granted.
The issue has since been fixed in the Facebook-v4 plugin.

Getting user app token using react-native facebook SDK

I've gotten facebook login working using the new https://github.com/facebook/react-native-fbsdk, however I can't seem to get the user token which is usually returned in the response. Anyone found a way to get this information? The other SDK's https://github.com/magus/react-native-facebook-login returns it on the login request but the new FB sdk doesn't, and the documentation on the github page doesn't mention it anywhere.
Found the answer after some more digging. You need to use the fbsdkcore to access the user token. Heres how you use it.
var FBSDKCore = require('react-native-fbsdkcore');
var {
FBSDKAccessToken,
} = FBSDKCore;
var Login = React.createClass({
render: function() {
return (
<View>
<FBSDKLoginButton
onLoginFinished={(error, result) => {
if (error) {
alert('Error logging in.');
} else {
if (result.isCanceled) {
alert('Login cancelled.');
} else {
FBSDKAccessToken.getCurrentAccessToken((token) => {
console.log(token.tokenString);
})
}
}
}}
onLogoutFinished={() => console.log('Logged out.')}
readPermissions={[]}
publishPermissions={['publish_actions']}/>
</View>
);
}
});
You don't need a third party module (react-native-fbsdkcore)
The package (react-native-fbsdk) has instructions on it's Github page: https://github.com/facebook/react-native-fbsdk#usage
After you've logged the user in, you can fetch the access credentials as follows:
import { AccessToken } from 'react-native-fbsdk';
AccessToken.getCurrentAccessToken().then(data => {
console.log(data.accessToken.toString())
})

Firefox SDK monitoring http response

This is mostly in reference to Firefox add-on SDK: Get http response headers. I am trying to log responses to http requests, but so far I am having no luck debugging this. Would really appreciate some advice... been banging my head on this for hours and gotten nowhere.
This is the main.js for my little extension:
var {Cc, Ci} = require("chrome");
var httpRequestObserver =
{
init: function() {
var observerService = Cc["#mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
observerService.addObserver( this, 'http-on-examine-response', false );
observerService.addObserver( this, 'http-on-examine-cached-response', false );
observerService.addObserver( this, 'http-on-examine-merged-response', false );
},
observe: function(subject, topic, data) {
if (topic === 'http-on-examine-response' || topic === 'http-on-examine-cached-response' || topic === 'http-on-examine-merged-response' ) {
subject.QueryInterface(Ci.nsIHttpChannel);
this.onExamineResponse(subject);
}
},
onExamineResponse: function(oHttp) {
try
{
console.log( oHttp.URI.spec );
}
catch(err)
{
console.log(err);
}
}
};
When I execute the firefox add-on sdk, the test browser boots up fine, and if I open Tools > Add-ons > Extensions, I see mine listed there. But when I point the test browser to google.com (or any url) nothing gets logged to the console.
I've compared my main.js to the techniques suggested # https://developer.mozilla.org/en-US/docs/Setting_HTTP_request_headers and everything seems to be congruent. In the end I plan to do something more complicated than just logging things, but I can't even get this basic functionality to work properly!
It seems that you set the observer for requests, not responses (http-on-examine-request).
Use this in the init function:
observerService.addObserver( this, 'http-on-examine-response', false );
observerService.addObserver( this, 'http-on-examine-cached-response', false );
observerService.addObserver( this, 'http-on-examine-merged-response', false );
Similarly, use this in the observe function:
if (topic === 'http-on-examine-response' || topic === 'http-on-examine-cached-response' || topic === 'http-on-examine-merged-response' ) { ... }