Skip to content

Commit

Permalink
Added "callPhoneNumber"
Browse files Browse the repository at this point in the history
  • Loading branch information
robgruen committed Nov 1, 2024
1 parent 6e84880 commit 3bacfa7
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 5 deletions.
1 change: 0 additions & 1 deletion android/samples/mobile/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions android/samples/mobile/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<uses-permission android:name="android.permission.CALL_PHONE" />

<uses-feature android:name="android.hardware.camera.any" android:required="true" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ class JavaScriptInterface(var context: Context) {
.putExtra(AlarmClock.EXTRA_MINUTES, t.minute)
startActivity(context, intent, null)
}

@JavascriptInterface
fun callPhoneNumber(phoneNumber: String) {
val uri = String.format(Locale.ROOT, "tel:%s", phoneNumber)
val intent = Intent(Intent.ACTION_CALL, Uri.parse(uri))
startActivity(context, intent, null);
}
}
3 changes: 2 additions & 1 deletion ts/packages/agentSdk/src/display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export type ClientAction =
| "open-app"
| "show-notification"
| "start-intent"
| "set-alarm";
| "set-alarm"
| "call-phonenumber";

export interface ActionIO {
readonly type: DisplayType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ActionResult,
} from "@typeagent/agent-sdk";
import { createActionResult } from "@typeagent/agent-sdk/helpers/action";
import { SetAlarmAction } from "./androidMobileSchema.js";
import { AndroidMobileAction, CallPhoneNumberAction, SetAlarmAction } from "./androidMobileSchema.js";

export function instantiate(): AppAgent {
return {
Expand Down Expand Up @@ -49,11 +49,17 @@ async function updateAgentContext(
): Promise<void> {}

async function handlePhotoAction(
action: SetAlarmAction,
action: AndroidMobileAction,
context: ActionContext<PhotoActionContext>,
) {
let result: ActionResult | undefined = undefined;
switch (action.actionName) {
case "callPhoneNumber": {
let callAction = action as CallPhoneNumberAction;
result = createActionResult(`Calling ${callAction.parameters.phoneNumber}`);
context.actionIO.takeAction("call-phonenumber", callAction.parameters);
break;
}
case "setAlarm": {
let alarmAction = action as SetAlarmAction;
result = createActionResult("Setting Alarm");
Expand Down
13 changes: 12 additions & 1 deletion ts/packages/agents/androidMobile/src/androidMobileSchema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

export type AndroidMobileAction = SetAlarmAction | UnknownAction;
export type AndroidMobileAction = CallPhoneNumberAction | SetAlarmAction | UnknownAction;

// calls a user's phone number but only if we know the phone number
export type CallPhoneNumberAction = {
actionName: "callPhoneNumber",
parameters: {
// the original request of the user
originalRequest: string;
// the phone number to dial
phoneNumber: string;
}
}

// sets an alarm on the local mobile device
export type SetAlarmAction = {
Expand Down
1 change: 1 addition & 0 deletions ts/packages/shell/src/lib/lib.android.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
declare var Android: {
showToast: (message: string) => void;
setAlarm: (time: string) => void;
callPhoneNumber: (phoneNumber: string) => void;
};
4 changes: 4 additions & 0 deletions ts/packages/shell/src/renderer/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ function addEvents(
Android?.setAlarm(d.time);
return;
}
case "call-phonenumber": {
let d: any = data;
Android?.callPhoneNumber(d.phoneNumber);
}
}
} catch (e) {
console.log(e);
Expand Down

0 comments on commit 3bacfa7

Please sign in to comment.