Differentiation between normal users and bots in Telegram - telegram

Say I have created a group in Telegram and want to develop a bot and add it to the group as an admin. Now, say this bot is programmed to send a welcome message to the users joining the group. However, we want to send the welcome message only to actual human users, and not to other bots that might have been added to the group. Is this technically possible? I mean, when I'm developing my admin bot, how can I make it able to differentiate between a user and a bot? Is there a query or something for that?

your bot gets a JSON object as a new user joins your group:
{
message_id: 8,
from: {
id: <user_id>,
is_bot: false,
first_name: 'A',
last_name: 'B',
username: '<adder_username>'
},
chat: {
id: <chat_id>,
title: 'test',
type: 'supergroup'
},
date: 1535443550,
new_chat_participant: {
id: <user_id>,
is_bot: false,
first_name: 's',
username: '<added_username>',
language_code: 'en-us'
},
new_chat_member: {
id: <user_id>,
is_bot: false,
first_name: 's',
username: '<added_username>',
language_code: 'en-us'
},
new_chat_members: [{
id: <user_id>,
is_bot: false,
first_name: 's',
username: '<added_username>',
language_code: 'en-us'
}]
}
checking msg.new_chat_participant.is_bot you can find out if it is a real user or a bot.

Related

Meteor not able to create user after adding attaching schema to users collection

I have installed mizzao:user-status package to track user activity like online, idle status.
I have added status to users collection:
import SimpleSchema from "simpl-schema";
const userSchema = new SimpleSchema({
status: {
type: Object,
optional: true,
},
"status.lastlogin": {
type: Object,
optional: true,
},
"status.lastlogin.date": {
type: Date,
optional: true,
},
"status.lastlogin.ipAddr": {
type: String,
optional: true,
},
"status.userAgent": {
type: String,
optional: true,
},
"status.idle": {
type: Boolean,
optional: true,
},
"status.lastActivity": {
type: Date,
optional: true,
},
"status.online": {
type: Boolean,
optional: true,
},
});
Meteor.users.attachSchema(userSchema);
On sign up page I have createUser code:
Accounts.createUser(
{ username, email, password },
async (error) => {
if (error && error.reason) {
setErrors({ signUpFailed: error.reason });
setIsLoading(false);
return;
}
navigate('/dashboard', { replace: true });
}
);
Whenever I try to register I get an error on the server:
Exception while invoking method 'createUser' Error: After filtering out keys not in the schema, your object is now empty
All fields in status are set to optional yet I am still getting this error. If I remove Meteor.users.attachSchema(userSchema); then create user works.
The error is pretty clear. In short it went through your schema, removed things that are not in it and found that it leaves you with empty object. As such you need to define all the other fields that is being used on the users collection. There are two ways how to avoid this issue. First is not to set any schema on the users collection, second is to properly describe everything that is being set and stored there. If you are adjusting the the user documents, then the second approach is best. Bellow is mine description, which also includes definitions for alanning:roles for quick reference. You can find more details on collection2 documentation:
https://github.com/Meteor-Community-Packages/meteor-collection2#attach-a-schema-to-meteorusers
const userSchema = new SimpleSchema({
username: {
type: String,
// For accounts-password, either emails or username is required, but not both. It is OK to make this
// optional here because the accounts-password package does its own validation.
optional: true
},
emails: {
type: Array,
// For accounts-password, either emails or username is required, but not both. It is OK to make this
// optional here because the accounts-password package does its own validation.
optional: true
},
'emails.$': {
type: Object
},
'emails.$.address': {
type: String,
regEx: SimpleSchema.RegEx.Email,
optional: true
},
'emails.$.verified': {
type: Boolean,
optional: true
},
'emails.$.primary': {
type: Boolean,
optional: true
},
createdAt: {
type: Date
},
profile: {
type: Object,
optional: true,
blackbox: true
},
services: {
type: Object,
optional: true,
blackbox: true
},
roles: {
type: Array,
optional: true
},
'roles.$': {
type: Object,
optional: true,
blackbox: true
},
// In order to avoid an 'Exception in setInterval callback' from Meteor
heartbeat: {
type: Date,
optional: true
}
})
You'll probably need to describe
username: {
type: String
},
emails: {
type: Array,
optional: true
},
at least, probably with other fields like profile
Sounds like what you are really looking for is https://docs.meteor.com/api/accounts-multi.html#AccountsServer-onCreateUser, which is the callback function you should use to add more fields to the user document when it is created. You don't really need to attach a schema for that, and from your comment the point of the schema was just to extend the user object somehow. If I understood that correctly, then onCreateUser is definitely the way to go.

Receiving "Unsupported element '$[operation]'." when running a mutation

I am having an issue running a mutation that was generated by the Amplify CLI.
I'm on node v14.18.1, amplify CLI 7.6.2.
I just recently migrated to the GraphQL Transformer v2.
Here is my model:
type User
#model
#auth(
rules: [
{ allow: groups, groups: ["admin"] }
{ allow: owner, ownerField: "id", operations: [read] }
]
) {
id: ID!
first_name: String
last_name: String
email: String!
customer: Customer #hasOne(fields: ["userCustomerId"])
userCustomerId: ID! #index(name: "usersByCreatedAt", queryField: "usersByCreatedAt" sortKeyFields: ["createdAt"])
createdAt: String!
isAdmin: Boolean
}
The mutation I'm calling from within AppSync:
mutation UpdateUser {
updateUser(input: {id: "asdfasdfasdf", isAdmin: true, last_name: "Franklin", first_name: "Tim", email: "tim#tim.com", userCustomerId: "my_customer"}) {
id
}
}
Error:
{
"data": {
"updateUser": null
},
"errors": [
{
"path": [
"updateUser"
],
"data": null,
"errorType": "MappingTemplate",
"errorInfo": null,
"locations": [
{
"line": 2,
"column": 3,
"sourceName": null
}
],
"message": "Unsupported element '$[operation]'."
}
]
}
Has anyone ran into this error, and how did you resolve it?
Thank you!
Check if there are any .vtl files in project_dir/amplify/backend/api/api_name/resolvers. If there are and you're not sure why/don't recognize them, back up and delete those files, deploy your local backend with amplify push, and see if the mutation succeeds.
I was getting the exact same error during a delete mutation and this resolved it for me. The Amplify CLI auto-generates templates for the API service, but overrides them with any it finds in that directory. Just make sure to back up all of those files before deleting them just in case..
Check what "Data Source" your resolver function is connected to. You can see this information in the AppSync web UI for the given resolver function. If the Data Source is not mapped to the correct place or if it's set to NONE_DS, then all of the operations for the given resolver function will fail.
This error happened to me when I accidentally connected the resolver to the RDS datasource instead of the DynamoDB one.

iOS Notification Images React-Native

I have a problem to display image in my ios notification. It works on android but not in ios.
I have followed the react-native-firebase documentation and it doesn't work ....
The documentation : https://rnfirebase.io/messaging/ios-notification-images
My code to receive the notification :
buildIOSNotification = (id, title, message, data = {}, options.
= {}) => { return {
alertAction: options.alertAction || 'view',
category: options.category || '',
userInfo: {
id: id,
item: data,
},
}}
And this is the json object that i receive :
{"action": undefined, "badge": undefined, "data": {"fcm_options": {"image": "http://192.168.1.37:4000/notification/46f72f09cfc29c6a8878dd23c4cee7d2"}, "gcm.message_id": "1622999135203061", "google.c.a.e": "1", "google.c.sender.id": "556656275748", "notificationId": "A5490592-7AA1-4B6F-82BF-3BA9D6589B0A", "remote": true}, "finish": [Function finish], "foreground": true, "id": undefined, "message": "dsdsdsdsdsdsdsdsdsdsdsddsdsdsdsddsdsddsdsdsdsdsdsdsds", "reply_text": undefined, "soundName": "sound_one.mp3", "title": "ddssddsdsdsdssdsddsddsdssdsdsdssdsdsdsdsdsdsd", "userInteraction": true}

Smart Home device implementing Alexa.Speaker Interface not responding to volume change request

My Alexa Smart Home Skill for Entertainment Devices implements a few capabilities of API version 3, including the Alexa.Speaker Interface.
As far as I understand from the documentation, it should respond to voice commands such as “Alexa, set the volume of device to 5”, however Alexa always responds with "Sorry, I can't control the volume on your device".
The discovery response of the device looks like this
{
endpointId: 'music1',
friendlyName: 'pillow',
description: 'Music on Kodi',
manufacturerName: 'Cubox-i',
displayCategories: [],
capabilities: [
{
type: 'AlexaInterface',
interface: 'Alexa.PowerController',
version: '1.0',
properties: {
supported: [
{
name: 'powerState',
},
],
},
},
{
type: 'AlexaInterface',
interface: 'Alexa.PlaybackController',
version: '1.0',
properties: {},
},
{
type: 'AlexaInterface',
interface: 'Alexa.Speaker',
version: '1.0',
properties: {
supported: [
{
name: 'volume',
},
{
name: 'muted',
},
],
},
},
],
}
The discovery seems to work fine, as the PowerController interface is being responded to fine (e.g. "Alexa, turn on pillow").
I can see discovery, PowerController and PlaybackController requests and responses in the AWS Lambda logs.
Any voice commands to Speaker (whether trying to set the volume to 20, increasing it by 5, or asking to mute or unmute pillow) do not produce any requests to my Lambda and result in the response mentioned above – or in the case of muting in "Pillow doesn't support that".
Instead of
properties: {
supported: [
{
name: 'volume',
},
{
name: 'muted',
},
],
},
this JSON ,use this:
'properties.supported':[{
name: 'volume',
},
{
name: 'muted',
}]
This is a bug they are trying to solve,but till then,this will work,please let me know if this particular solution works for you.
To addition to 'properties.supported' the version should be 1 (not 3). The Speaker interface discovery response should look like:
{
"type": "AlexaInterface",
"interface": "Alexa.Speaker",
"version": "1.0",
"properties.supported":[
{
"name": "muted",
},
{
"name": "volume"
}]
}

Method to update users role is giving an error when using Collection2 package

Here is my method:
removeRole: function(role) {
check(role, String);
var user = Meteor.user();
if (!user || ! AccountsAdmin.checkForAdminAuthentication(user))
throw new Meteor.Error(401, "You need to be an authenticated admin");
// handle non-existing role
if (Meteor.roles.find({name: role}).count() < 1 )
throw new Meteor.Error(422, 'Role ' + role + ' does not exist.');
if (role === 'admin')
throw new Meteor.Error(422, 'Cannot delete role admin');
// remove the role from all users who currently have the role
// if successfull remove the role
Meteor.users.update(
{roles: role },
{$pull: {roles: role }},
{multi: true},
function(error) {
if (error) {
throw new Meteor.Error(422, error);
} else {
Roles.deleteRole(role);
}
}
);
},
Here is the error I receive when looking at the call in Kadira:
message: After filtering out keys not in the schema, your modifier is now empty
stack:
Error: After filtering out keys not in the schema, your modifier is now empty
at [object Object].doValidate (packages/aldeed_collection2-core/lib/collection2.js:282:1)
at [object Object]._.each.Mongo.Collection.(anonymous function) [as update] (packages/aldeed_collection2-core/lib/collection2.js:83:1)
at [object Object].Meteor.methods.removeRole (packages/accounts-admin-ui-bootstrap-3/server/methods.js:86:1)
Line 86 of that methods.js is "Meteor.users.update" in the code above. When trying to debug this using breakpoints it appears this is where the error is happening as well.
I am using this package to help with the user management UI that I am creating, although I have did some customizing to it. I have also tested this on a different version of my project for troubleshooting and I have found that it works when I don't use the Collection2 package.
Here is my custom schema setup:
Schema = {};
Schema.UserProfile = new SimpleSchema({
userProfile: {
type: Object
},
'userProfile.firstName': {
type: String,
optional: true,
label: "First Name"
},
'userProfile.lastName': {
type: String,
optional: true,
label: "Last Name"
},
'userProfile.birthday': {
type: Date,
optional: true,
label: "Date of Birth"
},
'userProfile.contactEmail': {
type: String,
optional: true,
label: "Email"
},
'userProfile.gender': {
type: String,
allowedValues: ['Male', 'Female'],
optional: true,
label: "Gender"
},
'userProfile.address': {
type: String,
optional: true,
label: "Address"
},
'userProfile.city': {
type: String,
optional: true,
label: "City"
},
'userProfile.stateProvince': {
type: String,
optional: true,
label: "State/Province"
},
'userProfile.postalCode': {
type: String,
optional: true,
label: "Postal Code"
},
'userProfile.phoneNumber': {
type: String,
optional: true,
label: "Phone Number"
},
userProfilePayment: {
type: Object
},
'userProfilePayment.paymentEmail': {
type: String,
optional: true,
label: "Payment Email"
},
'userProfilePayment.address': {
type: String,
optional: true,
label: "Address"
},
'userProfilePayment.city': {
type: String,
optional: true,
label: "City"
},
'userProfilePayment.stateProvince': {
type: String,
optional: true,
label: "State/Province"
},
'userProfilePayment.postalCode': {
type: String,
optional: true,
label: "Postal Code"
},
'userProfilePayment.phoneNumber': {
type: String,
optional: true,
label: "Phone Number"
},
});
Schema.User = new SimpleSchema({
username: {
type: String,
// For accounts-password, either emails or username is required, but not both. It is OK to make this
// optional here because the accounts-password package does its own validation.
// Third-party login packages may not require either. Adjust this schema as necessary for your usage.
optional: true
},
emails: {
type: Array,
// For accounts-password, either emails or username is required, but not both. It is OK to make this
// optional here because the accounts-password package does its own validation.
// Third-party login packages may not require either. Adjust this schema as necessary for your usage.
optional: true
},
"emails.$": {
type: Object
},
"emails.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email
},
"emails.$.verified": {
type: Boolean
},
createdAt: {
type: Date
},
profile: {
type: Schema.UserProfile,
optional: true
},
// Make sure this services field is in your schema if you're using any of the accounts packages
services: {
type: Object,
optional: true,
blackbox: true
},
// Add `roles` to your schema if you use the meteor-roles package.
// Option 1: Object type
// If you specify that type as Object, you must also specify the
// `Roles.GLOBAL_GROUP` group whenever you add a user to a role.
// Example:
// Roles.addUsersToRoles(userId, ["admin"], Roles.GLOBAL_GROUP);
// You can't mix and match adding with and without a group since
// you will fail validation in some cases.
roles: {
type: Object,
optional: true,
blackbox: true
},
// In order to avoid an 'Exception in setInterval callback' from Meteor
heartbeat: {
type: Date,
optional: true
},
// Added to work with mizzao:user-status
status: {
type: Object,
optional: true,
blackbox: true
}
});
Meteor.users.attachSchema(Schema.User);
Meteor.users.allow({
// NOTE: The client should not be allowed to add users directly!
insert: function(userId, doc) {
// only allow posting if you are logged in
console.log("doc: " + doc + " userId: " + userId);
return !! userId;
},
update: function(userId, doc, fieldNames) {
// only allow updating if you are logged in
console.log("doc: " + doc + " userId: " + userId);
// NOTE: a user can only update his own user doc and only the 'userProfile' and 'userProfilePayment' field
return !! userId && userId === doc._id && _.isEmpty(_.difference(fieldNames, ['userProfile, userProfilePayment']));
},
/* NOTE: The client should not generally be able to remove users
remove: function(userID, doc) {
//only allow deleting if you are owner
return doc.submittedById === Meteor.userId();
}
*/
});
To remove a key in a mongodb update you want to use the $unset operator:
Meteor.users.update({ roles: role },{ $unset: { roles: 1 }}, { multi: true })
It's just a bit unusual that in your model a user can only have a single role.

Resources