I'm using the MadelineProto project for php to interact with Telegram API.
Maybe this error has nothing to do with MadelineProto... anyway, I successfully created a supergroup but any other method I call after, gives me a CHAT_WRITE_FORBIDDEN error.
Can't find anything in Telegram Documentation about why I'm getting this error and how to solve.
This is my code:
$MadelineProto = new MadelineProtoAPI('session.madeline', $settings);
$MadelineProto->async(false);
$MadelineProto->start();
// successfully create the group
$updates = $MadelineProto->channels->createChannel([
'megagroup' => true,
'title' => 'Test group',
'about' => 'Test group description',
]);
foreach($updates as $update) {
// try to invite other users --> CHAT_WRITE_FORBIDDEN
$updates = $MadelineProto->channels->inviteToChannel([
'channel' => $update,
'users' => ['########']
]);
// try to change admin rights --> CHAT_WRITE_FORBIDDEN
$updates = $MadelineProto->channels->editAdmin([
'channel' => $update,
'user_id' => '########',
'admin_rights' => [
'_' => 'chatAdminRights',
'change_info' => true,
'post_messages' => true,
'edit_messages' => true,
'delete_messages' => true,
'ban_users' => true,
'invite_users' => true,
'pin_messages' => true,
'add_admins' => true,
'anonymous' => true,
],
'rank' => ''
]);
}
What I'm doing wrong?
Thanks
It seems that the problem was due to the value passed to the 'channel' property. Instead of passing the $update variable, I passed directly the channel id in the form "channel#1234567890" and finally got a correct answer from Telegram.
Related
okay, this is my first time to ask a question here so please give grace if it's not very clear. Anyway, I have this code in Laravel Billing.php.
Is this correct? Whenever a new customer is created, it doesn't have it's user email address but instead this unknown#domain.com was assigned to the user.
This was set by my previous developer. But ever since we hired him for just simple fix, we've had numerous issues with the site.
$stripeCustomer = StripeCustomer::create([
'email' => $currentCustomer->email ? $currentCustomer->email : 'unknown#domain.com',
'description' => $company->name,
'metadata' => [
'company_id' => $company->id,
'card_owner_email' => $currentCustomer->email ? $currentCustomer->email : false,
'company_name' => $company->name,
],
]);
You can remove customer email from the StripeCustomer when creating since stripe API said that email field of customer is optional. Here is the reference link
Here what you should fix:
$customerObject = [
'description' => $company->name,
'metadata' => [
'company_id' => $company->id,
'company_name' => $company->name,
],
];
if ($currentCustomer->email) {
$customerMetadata["metadata"]["card_owner_email"] = $currentCustomer->email;
$customerObject["email"] = $currentCustomer->email;
}
$stripeCustomer = StripeCustomer::create($customerObject);
I want to make search in my project. I use typeahead but it's not working. This is my code:
<?php
echo '<label class="control-label">Select Repository</label>';
$template = '<div><p class="repo-language">{{no_telepon}}</p>' .
'<p class="repo-name">{{nama}}</p>' .
'<p class="repo-description">{{email}}</p></div>';
echo Typeahead::widget([
'name' => 'twitter_oss',
'options' => ['placeholder' => 'Filter as you type ...'],
'dataset' => [
[
'prefetch' => Penerima::find()->all(),
'datumTokenizer' => "Bloodhound.tokenizers.obj.whitespace('value')",
'display' => 'value',
'templates' => [
'notFound' => '<div class="text-danger" style="padding:0 8px">Unable to find repositories for selected query.</div>',
'suggestion' => new JsExpression("Handlebars.compile('{$template}')")
]
]
]
]);
?>
This question was asked long time a go.
I also faced the same problem, but i could figure-out this.
for future reference i add this post.
in your controller
$result = SampleModel::find()
->select('Attribute_name')
->where('name LIKE "%' . $searchParameter .'%"')
->asArray()
->all();
return Json::encode($result);
here you need to get the database value as "associative array", you can get that from using "asArray()".
then as you see return value as Json encode.
in your "View"
<?php
echo Typeahead::widget([
'name' => 'sampleName',
'options' => ['placeholder' => 'Filtering data ...'],
'scrollable' => true,
'pluginOptions' => ['highlight'=>true],
'dataset' => [
[
'remote' => [
'url' => Yii::$app->urlManager->createUrl(['sample/action']) .
'?searchParameter=%QUERY',
'wildcard' => '%QUERY'
],
'datumTokenizer' => "Bloodhound.tokenizers.obj.whitespace('Atribute_name')",
'display' => 'Atribute_name',
'limit' => 10,
],
],
'pluginEvents' => [
'typeahead:select' => 'function(e, s) {
EnableUserDetailsTypeAhead(s);
}',
]
]);
?>
here few things to be consider.
calling to the controller action. you can do that.
Yii::$app->urlManager->createUrl(['sample/action']) .
'?searchParameter=%QUERY',
'wildcard' => '%QUERY'
],
the below lines inside data set must be provide.
'datumTokenizer' => "Bloodhound.tokenizers.obj.whitespace('Atribute_name')",
'display' => 'Atribute_name',
you will get the expected data.
this sample code i have tested and this is working
From the docs:
prefetch: array, configuration for the prefetch options object. Refer documentation for the options you can set for this parameter. The return data must be Json encoded and converted to an associative array of the format [['value' => 'data1'], ['value' => 'data2'],...], where value is the fixed key set in display
You are passing an array of objects instead of an array of key value pairs. You can use asArray to create a list of objects. You will need to change display to the name of the field containing the data:
'prefetch' => Penerima::find()->select('title')->asArray()->all(),
I need to add a MailChimp subscriber to a specific grouping. I have no issue getting the subscriber subscribed, but can't seem to get them into a specific grouping.
This is what I have:
// ENTER INTO MAILCHIMP
$newsletter = $_POST['newsletter'];
$newsletter = 'yes';
if ($newsletter = "yes") {
$MailChimp = new \Drewm\MailChimp('api');
$result = $MailChimp->call('lists/subscribe',
array(
'id' => 'listnumber',
'email' => array('email'=> $_POST['usersEmail']),
'merge_vars' => array(
'FNAME'=>$_POST['usersName'], 'LNAME'=>$_POST['usersLastName'],
'groupings' => array(
'id' => 494281,
array(
'name'=>'KeepBoard',
'groups' => 'KeepBoardUsers'
)
)
),
'double_optin' => false,
'update_existing' => true,
'replace_interests' => false,
'send_welcome' => false
));
print_r($result);
}
Also I am not entirely sure where to grab the listing id. I can't seem to find documentation. I worked off the URL. But I don't think that is right because that is the id for all groupings.
For those that have this problem this was the issue. The groups have to be an array, even for a single group.
I have the following code:
$result = $ec2->runInstances(array(
// ImageId is required
'ImageId' => $image,
// MinCount is required
'MinCount' => 1,
// MaxCount is required
'MaxCount' => 1,
'KeyName' => $key,
'SecurityGroupIds' => array($sg),
'InstanceType' => $type,
'Placement' => array(
'AvailabilityZone' => $az,
),
'Monitoring' => array(
// Enabled is required
'Enabled' => false,
),
'SubnetId' => $subnet,
'PrivateIpAddress' => $ip,
'ClientToken' => 'string',
'AdditionalInfo' => 'string',
));
$instanceIds = $result->getPath('Instances/*/InstanceId');
$ec2->waitUntilInstanceRunning(array(
'InstanceIds' => $instanceIds,
));
this worked with no issues the first time I ran it. after initial run I terminated the instance from the EC2 console. now I am getting the following error every time I try to create a new instance.
A resource entered into an invalid state of "terminated" while waiting with the "InstanceRunning" waiter.
I do not understand why the waiter is looking at the old instance ID , is this somehow persisting?
Is there something else I need to add?
Solved this. it was an error on my part. I was setting the 'ClientToken' => 'string' which in turn would always try to query the previously created instance becuase 'string' was the unique id.
Following this question I gather that upsert: false and multi: true fields need to be set for this to work.
However, when I try to code this in PHP, I have a problem:
$conn = new Mongo("mongodb://foo:bar#localhost:27017");
$db = $conn->selectDB("someDB");
$data = array('$rename' => array(
'nmae' => 'name'
));
$db->command(array(
'findAndModify' => 'foo',
'update' => $data,
'upsert' => 'false',
'multi' => 'true'
));
After running this script, only the first document with the nmae typo is changed to name; the rest still say nmae. The same as if I had run it without the upsert and multi options.
I also tried this:
$data = array('$rename' => array(
'nmae' => 'name'
),
'upsert' => 'false',
'multi' => 'true'
);
$db->command(array(
'findAndModify' => 'foo',
'update' => $data
));
But that does the same thing.
Any way to get this working?
The findAndModify query doesn't have a "multi" option:
http://www.php.net/manual/en/mongocollection.findandmodify.php
What you probably want to use is update instead:
http://www.php.net/manual/en/mongocollection.update.php